unpause from a uifigure
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm used to using pause to run through a loop with plots and to pause until hitting return. Something like this:
for i = 1:100
plot(1:i)
pause
end
(Edit: to clarify, this is pressing return while focuse on the figure window)
Now however if the code launches a uifigure, it is unclear how to run the same code. Is there a way of programatically unpausing?
fig = uifigure;
ax = axes(fig)
for i = 1:100
plot(ax,1:i)
pause
end
I know I can use uiwait and uiresume but it is unclear why I can't get code to work that supports pause as well.
6 Kommentare
dpb
am 27 Jul. 2025
"if you click on a traditional figure, not the uifigure, and press return, execution advances past the pause"
Yes, but a uifigure ain't a regular old figure.
With the uifigure I think the uiwait is probably the only option.
One could file an enhancement request but I wouldn't hold out much hope for any change in behavior...
Antworten (1)
Image Analyst
am 28 Jul. 2025
I still don't understand the workflow. It sounds like you may have some existing figures (either old style figures or new style uifigures) on display somehow from some other process, and your user might click on some particular figure and then run your script to do stuff, including calling pause. Is that right so far? Or is your for loop code part of an app designer-built GUI? But it sounds like sometimes you programmatically create a new figure in your code and want to know how not to pause. Is that right?
"Now however if the code launches a uifigure, it is unclear how to run the same code. Is there a way of programatically unpausing?"
So if your code had a call to figure to create a figure, then you could just do
fig = uifigure;
ax = axes(fig)
for i = 1:100
plot(ax,1:i)
end
Now if there were no existing figures open yet and then your code ran and the first call to plot() created a new figure, then you can use findobj to search for how many plots there are in existence before getting into your loop. Then if it's 2 or more, set a flag. In the loop check the flag for whether you should call pause or not.
3 Kommentare
dpb
am 28 Jul. 2025
For the purpose, the traditional pause solution is certainly the logical way; I've used it on occasion for exactly the same purpose fairly frequently. For that situation, I don't see a better solution.
I haven't tried, but one of the key differences between uifigure and figure is that the 'HandleVisibility' property defaults to 'off' with uifigure instead to 'on'. Thus the uifigure never can become the current object and so functions that rely on gcf or gca can't accidentally change an app interface object.
I wonder if for the specific case setting it 'on' instead would then let the keyboard keypress work. It would be necessary to return it to its default state afterwards, of course.
User apps with an interface don't envision the use of keyboard input other than via text boxes or editable tables and the like so the particular usage probably wasn't ever considered as part of a design specification. For that use case, adding a control to Pause/Continue is probably what would be the recommended solution instead despite the added complexity.
Siehe auch
Kategorien
Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!