Making a matlab GUI and displaying a value from a iterative loop (on a seperate m file) on a staticText

5 views (last 30 days)
He everyone,
I have a large for-loop in a script (lets call it Part1.m), from which I would like to take a variable (var) and disply it on a gui static-text box, with the gui updating the value every loop. Suppose the Gui is 'Part2.fig' and the associated script is 'Part2.m', how would i accomplish this.
as an example, suppose the loop in Part1.m is:
for n=1:100
var=n*10;
end
at every iteration i woould like the value of var to be displayed on the Gui Part2.fig. How do I do this. The only answer i found as of now is https://de.mathworks.com/matlabcentral/answers/110164-how-to-get-dynamic-changing-text-or-data-in-matlab-gui-in-a-panel-window. however, I dont seem to be able to find a set function when i create the staticText gui.
Thanks in advance

Accepted Answer

Walter Roberson
Walter Roberson on 7 Nov 2016
handle_to_part2 = part2();
handles_part2 = guidata(handle_to_part2);
for n=1:100
var=n*10;
set(handles_part2.text1, 'String', num2str(var) );
drawnow;
end
Change the "text1" to the name of the tag inside part2.fig
The first line,
handle_to_part2 = part2();
is executing part2() so that part2 will tell you its figure number. The handles structure for a GUIDE-created GUI are attached to the particular figure, not to some kind of "project", so you need to find out which figure it is to retrieve the handles structure
  3 Comments
Walter Roberson
Walter Roberson on 19 Oct 2018
Sorry, I am not familiar with how app designer stores variables. I believe the design philosophy is not the same.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!