フィルターのクリア

pass a variable value from simulink to gui while running simulation

1 回表示 (過去 30 日間)
N/A
N/A 2014 年 11 月 19 日
回答済み: N/A 2014 年 11 月 21 日
I have a simulink model which generates the position of a link using simmechanics. I need to use this value for the gui graph, and live. Is there a solution to this problem, since simout is only post-execution?

採用された回答

Orion
Orion 2014 年 11 月 19 日
you can send your signal in an interpreted matlab function (or a S-function).
In this function (an external .m that you wrote), the code is executed at every step time during the simulation.
so you just have to get the handle of your gui components (with findall) and update your button / graphs wth the input signals.
  6 件のコメント
N/A
N/A 2014 年 11 月 20 日
Got 1). Used the following code:
function y = MyExternalFcn(MyInput)
MyGuiHandle = findall(0,'Tag','figure1');
handles=guihandles(MyGuiHandle);
MyAxeHandle = handles.axes1;
hold on;
plot(MyInput(1),MyInput(2),'b+');
This does capture my GUI but there seems to be no output displayed. Also Simulink execution time is set to 'inf' but execution stops after giving the error: 'Error using test (line 10)'; line(10) is plot... . Am I missing something here?
Orion
Orion 2014 年 11 月 20 日
I have no idea what your data are.
To debug your problem, just remember that you are using a Mfile.
So you can put a breakpoint at the line 10 (and others if you want), then start the simulation, and every time your Mfile is called, the simulation will pause and you'll be inside the function.
And then, this no longer Simulink, but classic Matlab debugging.

サインインしてコメントする。

その他の回答 (1 件)

N/A
N/A 2014 年 11 月 21 日
function y = MyExternalFcn(MyInput)
% get the handle of your GUI and the handles structure
% get the handle of your GUI
% global MyGuiHandle MyAxesHandle
MyGuiHandle = findall(0,'Tag','figure100'); %Tag of Figure
% assignin('base','MyGuiHandle',MyGuiHandle);
handles=guihandles(MyGuiHandle);
MyAxesHandle = handles.axes1;
axes(MyAxesHandle)
plot(MyAxesHandle,MyInput(1),MyInput(2),'bo');
y = 1;

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by