Effacer les filtres
Effacer les filtres

Pre Selecting Figures to plot

21 vues (au cours des 30 derniers jours)
David Harra
David Harra le 8 Avr 2022
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

Réponse acceptée

Image Analyst
Image Analyst le 8 Avr 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

Plus de réponses (1)

Voss
Voss le 8 Avr 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

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by