Running copies of a figure simultaneously?

1 次查看(过去 30 天)
I'm creating a GUI in GUIDE with a .fig file and would like the user to be able to have multiple copies of the figure open simultaneously. Is this possible and if so, how would I go about doing it?
My MATLAB version is R2021b (free trial)

回答(1 个)

Walter Roberson
Walter Roberson 2021-12-5
Edit the .m file produced by GUIDE.
Very early on, about line 25, you will see
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
If you change the 1 to 0 and save the file, then you will be able to have multiple copies of the GUI open simultaneously.
Caution: using guidata() to get or set handle properties, including what is done on your behalf to set the handles structure, is always figure-specific. If your user clicks on one of the GUI and changes a property there and your could uses guidata(hObject, handles) to update the "master" copy of the handles structure, then only that figure will be affected by the change. If you wanted to change the properties for all copies of the figures, you would have to use some other way rather than the handles structure.
At the same time, however, if your code happens to use findobj() to locate particular graphics objects, then unless you are very careful with the handleVisibility property, or you are very careful with the location you start searching from, then findobj() might find the objects in other figures as well. It is possible to be careful, but if you are using findobj() then you have to be careful.
If you have not happened to use GUIDE for a while before, then you might not happen to be aware that in MATLAB, "GUI" and "figure" and "window" are the same thing. Every different "window" (different figure number or different figure handle) can have behaviour associated with it, including buttons and scroll bars and so on. There is no such thing in MATLAB as a "drawing only" window: every window can potentially have its own interface. It is just common to create plot windows and not assign extra behaviour to them -- but you could.
So when you ask about having multiple copies of the "figure" open, then you are asking about having multiple copies of the control panel (GUI) open.
From time to time, I do encounter people who really do want multiple full copies of the control panel open. But more of the time, when people ask about multiple figures, they are thinking in terms of having multiple drawing areas all under the control of the same control panel. And for that situation, you would leave gui_Singleton at its default value of 1 and just open and close windows by code as you needed.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by