how can i save the output in simulink?

Hi there,
Is that possible to save multi-output in Simulink? I do have 100 different input. Each input will have different output, and I want to keep all those outputs resulted from 100 different input in a one mat file. Is that possible?
thanks

2 Comments

Jim Riggs
Jim Riggs on 20 Dec 2018
Edited: Jim Riggs on 20 Dec 2018
Your question is not clear to me.
It sounds like you have a simulink model that you want to run 100 times using 100 different input values, creating 100 corresponding output data sets.
Or, is it the case that you have 100 separate signals that you want to combine into a single output?
the first one is the problem
"you have a simulink model that you want to run 100 times using 100 different input values, creating 100 corresponding output data sets".
if you can help me, ı will be much-appreciated
It will save my time a lot.
CHEERS.

Sign in to comment.

 Accepted Answer

Jim Riggs
Jim Riggs on 20 Dec 2018
Edited: Jim Riggs on 20 Dec 2018
I think that the best way to accomplish this is set up the Simulink model so that is saves the output to the Matlab workspace using a "To Workspace" block. Then, make a script file that will run the Simulink model, providing the desired inputs. In the script file, after the simulink model has run, put the output into a Matlab structure (you can put the inputs in the structure too). Use a loop in the script file to execute all of the model runs, saving the inputs and outputs each iteration in the data structure. This way, you can hold 100 sets of data (inputs and outputs) in a single structure. When done, save the data structure to a .mat file using the Matlab "save" command.

4 Comments

THANKS, I got everthing apart from " Use a loop in the script file to execute all of the model runs"
do you mean like this ? can you please give just that part in a code ?
for i=input1:input100;
simout_all=simout(i)
end
save('simout_all')
Jim Riggs
Jim Riggs on 21 Dec 2018
Edited: Jim Riggs on 21 Dec 2018
It would look something like:
for i=1:100
clear output
input = Input(i); % "Input()" is a vector containing 100 input values
sim('SimulinkModel'); % Call to Simulink model which refers to "input" to run
% The simulink model writes data to the matlab workspace variable "output"
Data(i).input = input;
Data(i).output = output;
end % Run the simulation 100 times using 100 diferent inputs. Save results in structure "Data"
Save('Simout',Data); % Simout" is the file name, Data is the Matlab structure
This assumes that your Simulink model is set up to use variable "input" from the Matlab workspace, i.e. somewhere in the model there is a block that refers to "input".
Jim Riggs
Jim Riggs on 21 Dec 2018
Edited: Jim Riggs on 21 Dec 2018
For example, suppose I create a Simulink model named "MyWave" that generates a sine wave. It multiplies the wave amplitude by "ampl". Variable ampl is defined in the matlab workspace. The "To Workspace" block is set up to save the output signal to the matab workspace as an array in variable "output".
I run this model using a script to define the required amplitude:
ampl = 5;
sim ('MyWave');
After the model runs, variable "output" contains the result, a sine wave with amplitude 5. The size of "output" depends on the settings for the Simulink model, i.e. how long to run, and what time step to use.
thank you so much. appriciate your explanation, Jim @Jim Riggs

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!