simulation inside a "for loop" for stop time

1 view (last 30 days)
I have simulink model running inside a for loop from script,,,will it gives to workspace data to workspace if i pause my simulation before reaching the last update of the for loop
  2 Comments
Doug Hull
Doug Hull on 19 Dec 2012
Have you tried? What happened when you tried it?
Arun Badigannavar
Arun Badigannavar on 20 Dec 2012
I tried,,,up to it finishes for loop it wont give you results to workspace,,,or else u have to forcefully stop it by Ctrl+C

Sign in to comment.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 20 Dec 2012
Arun, I've tested an example, and find some problems, when you pause or stop your simulink model, the output variable takes a certain time to be in workspace, so you have to insert a pause(n) after each simulation pause or stop. The problem is not related to the for loop
clear t y
close_system('filname',0)
close
%-------------------creating a model---------------------------------------
fic1='filname'
new_system(fic1)
open_system(fic1)
add_block('simulink/Sources/Step','filname/step1')
add_block('simulink/Continuous/Transfer Fcn','filname/syst1')
set_param('filname/step1','Position', [10 150 40 180 ] )
set_param('filname/syst1','Denominator','[1000 1]')
add_block('simulink/Sinks/To Workspace','filname/tw1')
set_param('filname/tw1','SaveFormat','array')
set_param('filname/tw1','VariableName','y')
add_line('filname','step1/1','syst1/1');
add_line('filname','syst1/1','tw1/1');
set_param('filname','StopTime','inf')
add_block('simulink/Sources/Clock','filname/tim')
add_block('simulink/Sinks/To Workspace','filname/tw2')
add_line('filname','tim/1','tw2/1');
set_param('filname/tw2','Position', [200 350 230 380 ] )
set_param('filname/tw2','SaveFormat','array')
set_param('filname/tw2','VariableName','t')
%--------------------------------Simulation--------------------------------
for k=1:2
if k==1
set_param('filname','SimulationCommand','start')
pause(1)
set_param('filname','SimulationCommand','pause')
pause(1)
plot(t,y,'or');
else
%-------------------------update---------------------------------------
set_param('filname/syst1','Numerator','[10]')
set_param('filname','SimulationCommand','continue')
pause(1)
set_param('filname','SimulationCommand','stop')
pause(1)
hold on
plot(t,y,'-g')
end
end
  2 Comments
Arun Badigannavar
Arun Badigannavar on 20 Dec 2012
Thanks a lot,,,without pausing is it posiible to send data continuosly to base workspace?because i want to use the data in the workspace at that time,,and proseess the simulation without pausing,,is it possible to access the workspace simulation data?
Arun Badigannavar
Arun Badigannavar on 20 Dec 2012
function doit
tic
launch;
t=timer('TimerFcn', @fun, 'ExecutionMode', 'fixedRate', 'Period', 1);
function fun(obj,event)
set_param(gcs,'Simulationcommand','start')
end
start(t)
% pause(1)
stop(t)
% delete(t)
toc if true
% code
end
end
This is how I am calling my simulink model every second and executing,, meantime i want data from blok "to workspace" data available in my workspace after each update bcoz i want use perticular time data for my further processing

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!