When are outputs of a function updated?

1 view (last 30 days)
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 Comment
Fabian Gock
Fabian Gock on 18 Jul 2018
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.

Accepted Answer

Steven Lord
Steven Lord on 18 Jul 2018
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.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!