Using SimEvents results in Matlab

1 Ansicht (letzte 30 Tage)
Zahra Moussavi
Zahra Moussavi am 28 Jan. 2016
Kommentiert: Zahra Moussavi am 2 Feb. 2016
Hi,
I want to change a parameter from 1 to 60 (1:1:60) in SimEvents and run the simulation. I might need to that for other parameters too so I thought of using a for loop in Matlab to do that. I used the "To Workspace block" to export my simulation results into the worksapce and when I run my simulation it is working and I can see the results being stored in an array. But the problem is when I use the for loop in Matlab to run the simulation then I get an error and it is not working. Any idea that why is it working when I run the simulation model itself and it's not when I run it from the Matlab environment?
Here is my simple code in Matlab:
clc
close all
Period = 0;
for i=1:60;
Period=Period+1;
sim('concreting1','SaveOutput','on','OutputSaveName','Timing');
SumTruckWaitTime=sum(simout(:,1))
MaxTruckWaitTime=max(simout(:,1))
end
That's is the warning that I get:
Reference to a cleared variable simout.
Error in IntervalChange (line 10)
SumTruckWaitTime=sum(simout(:,1))
That's the to workspace block in my simulation model:
and it is actually working when I run it from the SimEvents environment:

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 29 Jan. 2016
Assign the output of sim to simOut.
simOut = sim('concreting1', 'SaveOutput','on');
z = simOut.get('Finaloutput'); % Finaloutput being the name of the output you want
And
  2 Kommentare
Zahra Moussavi
Zahra Moussavi am 29 Jan. 2016
It worked! Cheers
Zahra Moussavi
Zahra Moussavi am 2 Feb. 2016
Hi again,
I need to store the time that an event occurred in the simulation too. For instance an entity leaving a queue in a specific time. How should I make this work? I am trying to use 'SaveTime', 'on' and the "Discrete Event Signal to Workspace" block but, I can't make it work!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Discrete-Event Simulation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by