How to run a Simulink simulation with a push button?
이전 댓글 표시
I'm a beginner. My simulation works OK in Simulink. It also works from Matlab command prompt. I can't run it from GUI. I'd like to start my simulation with a push button. I edited some code in GUI genareted m-file:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sim('MySimulation.mdl');
My simulation doesn't start. I don't see any array or structure in Matlab workspace. Why?
답변 (3개)
Paulo Silva
2011년 6월 23일
%load or open the model if it isn't already
open_system('MySimulation.mdl') %load_system('MySimulation.mdl')
set_param('MySimulation.mdl', 'SimulationCommand', 'start')
You don't see any exported variable because it didn't simulate or you just forgot to use To Workspace blocks or to select some variables to export on the simulation configuration.
댓글 수: 2
Walter Roberson
2011년 6월 23일
... Or the output went to a different workspace than was examined ?
Paulo Silva
2011년 6월 23일
Walter I woudn't go that far, the default behavior is to send to MATLAB workspace unless someone changes it on purpose.
rewerr
2011년 6월 23일
0 개 추천
댓글 수: 2
Paulo Silva
2011년 6월 23일
Ok Walter might be right, do this and try again
opts = simset('DstWorkspace','base')
sim('MySimulation.mdl',[], opts);
rewerr
2011년 6월 23일
rewerr
2011년 6월 23일
0 개 추천
댓글 수: 2
Paulo Silva
2011년 6월 23일
So the problem was solved but returned, you give no details how you are doing the code, the things you are expecting to go to the MATLAB workspace are really going to the GUI workspace, you can see it by doing the function who after the simulation (who goes inside you GUI code right after the sim or set_param), let me guess some workarounds:
[t,x,y] = sim(model,timespan,options);
assignin('base','t',t); %save the t to MATLAB workspace
assignin('base','y',y);
or if you use the set_param to start it do the assignin the next lines, so the variables exported by the simulation can be saved into your MATLAB workspace
rewerr
2011년 6월 23일
카테고리
도움말 센터 및 File Exchange에서 Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!