MATLAB Answers


When are outputs of a function updated?

Asked by Fabian Gock on 18 Jul 2018
Latest activity Answered by Steven Lord
on 18 Jul 2018
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, ..)
info="subfunction completed";
info="subfunction2 completed";
and in the GUI:
function ButtonPushed(app, event)
app.TextArea.Value = run_simulation(in1, in2..);
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 Comment

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?

Sign in to comment.

1 Answer

Answer by Steven Lord
on 18 Jul 2018
 Accepted Answer

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;
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.


Sign in to comment.