# Welcome!

Welcome to the MATLAB Central Simulink blog! The purpose of this blog is twofold: First, I want to share Simulink tips and tricks that I've learned over the years. At the same time, I hope to learn from you about your experiences with Simulink. Where is it good? How can we improve it?

I've been using Simulink for 9 years, first as a member of our technical support team, and then as a trainer. I still remember when I first learned about the power of Simulink as a newly hired support engineer back in 1998. During a training class I saw differential equations drawn on a whiteboard and then simulated with a few clicks of the mouse. I got excited by how clearly it all worked. Simulink provided me with a framework for thinking about systems and the relationships between their basic components.

• solvers
• sample times
• modeling
• hacks
• blocks
• model reference
• libraries
• custom code

An example: batch simulation

Let me start off with a specific example about running simulations. Simulink models are built using block diagrams, and once they've been created most everyone runs them by clicking the run button on the toolbar.

If you have to run a sweep of parameters you might change the parameter and then click run, change it again and click run. But if you have to run hundreds or thousands of simulations while modifying a parameter you will want to write a script for batch simulation. You can run simulations directly from MATLAB with the sim command like so.

>> [t,x,y] = sim(sys);

This returns the root level outputs (y) and the internal states of the model (x) at each recorded time step (t). A batch script might look like this:

open_system('vdp_mu')
muSweep = .5:.1:1.5;
for i = 1:length(muSweep)
mu = muSweep(i);
[t,x,y] = sim('vdp_mu');
plot(t,y); hold on;
end
title('VDP States for mu=.5 to 1.5')
xlabel('Time'); legend('x1','x2')

If you are already familiar with the sim command, then you probably know that some times you are only interested in the outputs (y) of the model, and not the states (x). For large models, or long simulations, those state variable outputs could be a waste of valuable memory. Using simset you can provide additional options to the sim command to specify that you only want time (t) and outputs (y). The state variable returned from sim will be empty.

[t,x,y] = sim('vdp_mu',[],simset('OutputVariables','ty'));
whos t x y
  Name        Size            Bytes  Class     Attributes

t         206x1              1648  double
x           0x0                 0  double
y         206x2              3296  double



What do you think?