I want to browse a directory where many Matlab GUI'开发者_如何学Cs (.fig files and their related .m files) are stored and change them systematically. For each, I want to search for a certain popup menu and, if it exists, delete some specific options.
I usually use get() and set() or similar functions to fiddle with GUI's, but these functions require handles, and I don't know how to get handles when not running the GUI, and also I wouldn't know how to save the changes.
If I open a .fig as text it is unintelligible.
I'm considering opening each at a time in guide (Matlab's GUI development environment) and changing it manually, but really would like to avoid it. I'm talking about tens of files, and my action might have to change in the future.
Maybe there would be a way to control guide from the command line? Or another solution?
You can load the .fig files using hgload
or openfig
. Both these functions return the figure's handle.
Once you have the figure's handle you can use findobj
to get the popup menu's handle. Then set
and get
as normal to change the menu's options, and then save the modified figure using hgsave
.
For example:
f = hgload('file.fig');
menuH = findobj(f, 'Type', 'popup');
set(menuH, 'String', new_options);
hgsave(f, 'file.fig');
gcf() immediately after open() gets the handles and can be done programatically for many figures.
精彩评论