Why does gcf in a GUIDE figure give the parent?

2 views (last 30 days)
Hello,
I've created a number of GUIDE windows called within one app, and one of them I would like to maximize. I have tested that window with a .m test file, and it works fine using
fh = gcf
fh.Window = 'Maximize'
If I insert this in the overarching GUIDE program (that's also a GUIDE figure), it won't maximize because the calling app figure is non-resizable. Obviously I am missing something regarding how the current figure gets passed to the child.
Thoughts? Thanks!
Doug

Accepted Answer

Walter Roberson
Walter Roberson on 4 Mar 2022
A figure becomes the current figure under any of the following circumstances:
  • the figure is created with figure() [or some routine calling figure() that ends up creating a figure]
  • the figure is made active by calling figure() and passing in a reference to the figure
  • any part of the figure is clicked in (and hit testing is on for any layer of the figure at that location)
If a figure is the current figure and it is deleted, then generally speaking, no other figure will necessarily become the current figure -- they are not defined as "stacking". However, some of the behaviour with creating dialogs such as inputdlg() tends to flow as-if it was going back to the figure that was active at the time the dialog or message was created (those dialogs and pop-up messages are actually figures.) Testing would have to be done to see exactly how that happens.
So... if your overarching GUIDE program is calling into the other GUIDE window because the user clicked something in the overarching GUIDE program... then that overarching GUIDE program became the current figure.
GUIs and figures are the same thing to MATLAB: a GUI is just behaviour attached to a figure, and any figure can have behaviour attached to it.
In your case, if you need the secondary GUIDE program to be able to find its handles by using gcf, then in the overarching program, use figure() passing in the handle of the secondary GUIDE program to make it the current figure.
  1 Comment
Douglas Anderson
Douglas Anderson on 4 Mar 2022
Edited: Douglas Anderson on 4 Mar 2022
Thank you very much, Walter, once again.
I am not sure how to "use figure() passing in the handle of the secondary GUIDE program". Each of them is created as .fig files, and I have plotted axes (successfully in the test case), so I want to display and print the called figure. The calling program, after a button press, just sends different parameters to this program (plot_spectra) to determine what type of spectrum to plot, and what to do with the plot (print, save, discard, etc.) based upon which button is pressed.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!