simulation inside a "for loop" for stop time
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Azzi Abdelmalek
2012 年 12 月 20 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Naming Conventions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!