Pre Selecting Figures to plot
22 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Image Analyst
on 8 Apr 2022
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
0 Comments
More Answers (1)
Voss
on 8 Apr 2022
% 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
0 Comments
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!