When are outputs of a function updated?

1 回表示 (過去 30 日間)
Fabian Gock
Fabian Gock 2018 年 7 月 18 日
回答済み: Steven Lord 2018 年 7 月 18 日
Hi,
I am currently working on a GUI project (AppDesigner). Now I want to implement a textarea, where I display the progress of the function, that is started with the GUI. My plan was, to add an output to the function, named info, which contains a string that is updated at several points in the function. In the GUI, this output is simply handed to the textarea.
info = run_simulation(in1, in2, ..)
out1=subfunction1(in1);
info="subfunction completed";
out2=subfunction2(in2);
info="subfunction2 completed";
end
and in the GUI:
function ButtonPushed(app, event)
app.TextArea.Value = run_simulation(in1, in2..);
end
Is the output of the function run_simulation updated immidiately, so that always the current value of info is displayed in the GUI, or do I only get the second string when run_simulation is completed?
Thanks in advance for any help -Fabian
  1 件のコメント
Fabian Gock
Fabian Gock 2018 年 7 月 18 日
So, I tried it with the perception, that the output is updated at the end of a function and it does not work as intended.
Does anyone know a workaround that does what I want?

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

採用された回答

Steven Lord
Steven Lord 2018 年 7 月 18 日
Have your run_simulation function accept an input that gives it access to the GUI (in this case, either app or app.TextArea would probably be easiest) and use that input to update the text box's value.
To make it clear what's going on, and to potentially allow you to change how the status is reported in the future, I'd create a function named updateStatus or something similar and call it whenever you want to update that status message.
function updateStatus(handleToTextArea, statusMessage)
handleToTextArea.Value = statusMessage;
end
If later on you wanted to write the statusMessage to a file, you could easily update this one function and have to make minimal changes to the places where it is called (which will be easy to find since you can search for the function name updateStatus.) You also could set a breakpoint in it to debug whenever the app's status changes, to ensure that the status changed at the appropriate time.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by