필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Albert Bing
Albert Bing 2020년 12월 26일
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

답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by