Pre Selecting Figures to plot

13 次查看(过去 30 天)
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 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by