필터 지우기
필터 지우기

Pre Selecting Figures to plot

조회 수: 21 (최근 30일)
David Harra
David Harra 2022년 4월 8일
답변: Image Analyst 2022년 4월 8일
When I run my script I have 10+ figures plotting. Rather than commenting them out, I was wondering if there is a way to set up at the beginning where I can select what plot or plots I would like. I was researching listdlg command but cant seem to implement this.
Thanks
Dave

채택된 답변

Image Analyst
Image Analyst 2022년 4월 8일
Try this:
for k = 1 : 10
choices{k} = sprintf('%d', k);
end
uiwait(helpdlg('On the next window, pick which you want to plot.'))
% Have specify which plots he wants to make
selectedIndexes = listdlg('ListString', choices)
if isempty(selectedIndexes)
% User clicked Cancel.
return;
end
% Do the selected plots:
for k = 1 : 10
if ismember(k, selectedIndexes)
subplot(3, 4, k);
plot(rand(10, 1), '-')
grid on;
caption = sprintf('Plot #%d', k);
title(caption)
end
end

추가 답변 (1개)

Voss
Voss 2022년 4월 8일
% some data you may or may not plot:
F = randn(10,1);
P = rand(20,1);
D = randi(50,25,1);
% prompt the plot selection:
plot_names = {'F' 'P' 'D'};
plot_idx = listdlg( ...
'Name','Select Plots', ...
'ListString',plot_names);
% make a logical vector saying whether to plot each plot:
do_plot = false(size(plot_names));
do_plot(plot_idx) = true;
% create the selected plots:
if do_plot(1)
figure();
plot(F);
title('F')
end
if do_plot(2)
figure();
plot(P);
title('P')
end
if do_plot(3)
figure();
plot(D);
title('D')
end

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by