How can I store the properties of a figure in MATLAB, then reset them at a later time?
1 view (last 30 days)
Show older comments
I want to store the properties of a figure in order to reset the figure's current configuration at a later time. For example, I would like to read my figure's properties using:
line
props = get(gcf);
Then, after having made some changes, I would like to reset all properties using:
fnames = fieldnames(props);
for n = 1:length(fnames)
set(gcf,fnames{n},props.(fnames{n}))
end
However, I obtain the following error:
??? Error using ==> set
Attempt to modify read-only figure property: 'BeingDeleted'.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The GET function returns properties that are read-only and cannot be set using the SET function.
The best method for storing a figure's properties, then resetting them at a later time, is to use the SAVEAS function to save the figure as a FIG-file.
saveas(gca, 'foo', 'fig');
Then, you can load this figure using the OPEN function:
open('foo.fig');
However, if you would like to store the properties in a variable, you can avoid the read-only properties when resetting the figure. The read-only properties of a figure are specified as:
readonly = {'BeingDeleted','CurrentCharacter','CurrentObject','FixedColors','Type'};
Then, the figure properties can be reset using:
props = rmfield(props, readonly);
fnames = fieldnames(props);
for n = 1:length(fnames)
set(gcf,fnames{n},props.(fnames{n}))
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Import Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!