simulation inside a "for loop" for stop time
이전 댓글 표시
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
Doug Hull
2012년 12월 19일
Have you tried? What happened when you tried it?
Arun Badigannavar
2012년 12월 20일
답변 (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
카테고리
도움말 센터 및 File Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!