私には2つのアイデアがありました:
「ファイル>コードの生成...」機能を使用します。MATLABは、インタラクティブに行った変更を加えて図を再作成する関数を作成します。
操作されたオブジェクトの対象となるプロパティを手動で取得し、スクリプトを再実行するときにそれらを再度適用します。これらのグラフィックスオブジェクトのハンドルのリストを維持するか
'Tag'
、FINDOBJ関数と組み合わせてそのようなオブジェクトを見つけることもできます。
後者のアイデアを例を挙げて説明します。
スクリプトを初めて実行するときに、ユーザーがインタラクティブに図を変更できるようにします。完了したら、'Position'
Figureとその中に含まれるすべての子コンポーネントのプロパティを取得します。これらの値は、MATファイルに保存されます。
ここで、ユーザーはいくつかのパラメーターを調整し、スクリプトを再実行します。MATファイルの存在を確認します。存在する場合は、保存された位置の値をロードし、それらをフィギュアとその子孫オブジェクトに適用して、コンポーネントを最後に保存された状態に復元します。
このソリューションはかなり単純なので、グラフィックハンドルの階層を壊してスクリプトに変更を加えた場合は、MATファイルを削除して、スクリプトを再実行する必要があります。
%# close all figures
close all
%# your script which creates figures
figure, plot(rand(100,1))
figure
subplot(121), plot( cos(linspace(0,6*pi,100)) )
subplot(122), image, axis image, axis ij
%# check for MAT-file
if exist('script_prefs.mat','file')
%# load saved values
load script_prefs.mat
%# get opened figures, and find objects with a position property
fig = get(0, 'Children'); %# allchild(0)
obj = findobj(fig, '-property','position');
try
%# apply values to position property
set(fig, {'Position'},figPos);
set(obj, {'Position'},objPos);
catch
%# delete MAT-file
delete script_prefs.mat
end
else
%# get opened figures, and find objects with a position property
fig = get(0, 'Children');
obj = findobj(fig, '-property','position');
%# wait for the user to finish customizing
waitFig = figure('Menubar','none', 'Position',[200 200 200 40]);
h = uicontrol('Units','normalized', 'Position',[0 0 1 1], ...
'String','Done?', 'Callback','uiresume(gcbf)');
uiwait(waitFig);
close(waitFig);
%# get position property of figures and tagged objects
figPos = get(fig, 'Position');
objPos = get(obj, 'Position');
%# save values to file
save script_prefs.mat figPos objPos
end