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