필터 지우기
필터 지우기

How do I pass Simulink variables from the “Configuration Parameters” to a GUI created using GUIDE?

조회 수: 8 (최근 30일)
I have a GUI created in GUIDE that: 1. Selects a test data CSV file to be simulated from my directory and 2. Allows the user to press “Start” to begin Simulink simulation. The GUI is communicating with Simulink. The Simulink model has a Stateflow model included that is used for trouble shooting control logic. The GUI is implemented to allow someone not familiar with the design of the Simulink/Stateflow model to be able to trouble shoot any test data CSV file easily.
The problem I am having errors with is when pressing the pushbutton “start” in the GUI.fig that is associated with starting the Simulink model. In my GUI.m file for the “start” pushbutton function, I have “sim SimulinkModel” and than also call some plots that compare test data with simulated data. The errors come from the plots, where variables cannot be found, “??? Undefined function or variable 'sim_time'. “.
These variables are defined in the Simulink “Configuration Parameters”, accessed by pressing Ctrl+E while viewing the Simulink model. I am saving, “Save to Workplace”, these variables, i.e. “Time”, “Output”. How do I pass these variables from the Simulink model to the GUI so when I execute the GUI pushbutton “start” I can get the simulation to work? Note, the Simulink simulation works without any error when pressing “Start simulation” from Simulink.
I believe this is something that needs to be added to the GUI.m file for the pushbutton function.
Thank you for the help.

채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 11월 28일
I think the problem might that you are defining the variables (sim_time, etc.) in the function workspace of your GUI, but the Simulink model is looking for them in the base workspace.
To ask Simulink to look in the function workspace, try:
options = simset('SrcWorkspace','current', 'DstWorkspace', 'current');
sim('SimulinkModel', options);
  댓글 수: 2
Andres
Andres 2012년 11월 28일
Thank you. This worked with a little editing. I changed 'current' to 'base' and also corrected the "sim" line to reflex the newer format:
options = simset('SrcWorkspace','base', 'DstWorkspace', 'base');
sim('SimulinkModel', [], options);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Babak
Babak 2012년 11월 28일
Look up
slConfigUIGetVal
in MATLAB help.

카테고리

Help CenterFile Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by