Filter löschen
Filter löschen

Does `uiopen('p​ath\to\pic​.fig')` reset the user modified toolbars?

2 Ansichten (letzte 30 Tage)
Albert Bing
Albert Bing am 26 Dez. 2020
I wrote a GUI program. It saved figures automatically by certain rules. For convenience I changed some toolbars of the figure, and they worked just fine when the figure was created. But when that figure was closed and reopened using uiopen('\path\to\pic.fig'), the modified toolbars functioned as the default ones.
So does uiopen just reset the toolbars? Is it possible to save the modified toolbars with figure permanently?
Here is a example of my script.
f = figure;
mesh(peaks);
legend('test');
f.UserData.pic_name = 'peaks_test';
f.UserData.pic_path = '.';
f.UserData.fig_path = 'fig'; % make sure the folder 'fig' exist
function auto_save_figure(fig)
ftb = findall(fig, 'Tag', 'FigureToolBar');
ftbs = findall(ftb);
h1 = findobj(ftbs, 'Tag', 'Standard.NewFigure');
h2 = findobj(ftbs, 'Tag', 'Standard.FileOpen');
h3 = findobj(ftbs, 'Tag', 'Standard.PrintFigure');
h4 = findobj(ftbs, 'Tag', 'DataManager.Linking');
set([h1, h2, h3], 'Enable', 'off');
set(h4, 'Enable', 'off');
save_fig = findobj(ftbs, 'Tag', 'Standard.SaveFigure');
save_fig.ClickedCallback = @auto_save; % when the user modified the figure, like legend, title, etc.
% the previous "save" button would save the changes automatically.
end
function auto_save(hObj, ~)
resolution = '-r160';
fig = ancestor(hObj, 'figure');
pic_name = fig.UserData.pic_name;
pic_path = fig.UserData.pic_path;
fig_path = fig.UserData.fig_path;
print(fig, fullfile(pic_path, [pic_name, '.png']), '-dpng', resolution);
saveas(fig, fullfile(pic_path, fig_path, [pic_name, '.fig']));
end

Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by