When are outputs of a function updated?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Introduction 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