1
votes

I have designed a model in simulink. Generally, I generate a plot by setting the values of blocks(eg.gain) in the model and simulating the model and opening the scope block. But I need to generate different grpahs corresponding to different values of blocks(eg.gain). Basically, for different values of Gain value, I want different graphs but all in the same plot. The different values I give to my gain should be from an array. This is my model enter image description here

I am using MATLAB for the first time. Please answer this in a beginner's approach

1
For a model this simple, all you need to do is put your whole vector of values into the gain block. Simulink will simulate the model as if you are simulating n-models in parallel (assuming an n-element vector) and display the results for all n-models in the same scope. However, as your models become more complex this will not be possible, and you should follow the approach given in @Tom Youngs answer.Phil Goddard

1 Answers

2
votes

Setting The Gain Value

The values of the gain blocks can be can be set as variables rather than constants i.e. you can give a gain block the value of K in the settings panel.

You can then create a script that gives K a value e.g;

%script to set gain and run model
K=2;
sim('Model Name Here');

This will set the value for your gain block and run the model.

Saving The Output

In the sinks section of the simulink library browser is a block called To Workspace, this allows you to send any output value to the MATLAB workspace in multiple formats with a name that you define.

Simulink 'To workspace' block

Your simulink model will now look something like this;

Simulink Model with output block

Now you can create a script that sets a gain value for your model, runs the model and saves the output to your workspace. With a couple of for loops and you can produce an array of inputs and outputs for your system.

From here you should be able to plot the inputs and outputs on the same graph using the well documented plot function.