Plot multiple separate figures

3 vues (au cours des 30 derniers jours)
BN
BN le 12 Avr 2020
Commenté : Ameer Hamza le 12 Avr 2020
Dear all,
I have a table with two rows, I have a code to plot a pie chart for a first row, Now for each row I want to have a separate figure. In fact, I want to have a loop to generate a pie chart for each row and save it as a figure in the current folder. I tried some ways but all of them gives me various errors.
Here is the code:
clf
p = pie(ones(1,5));
t = p(2:2:end);
p = p(1:2:end);
delete(t)
s = {'CC', 'ME', 'NU', 'BI', 'IA'};
for i=1:5
switch davar1.([s{i} '_CHECK']) % I even tried insert (j) here and do it in the for loop but error says Index exceeds the number of array elements (2).
case 'New York'
p(i).FaceColor = 'g';
case 'California'
p(i).FaceColor = 'y';
case 'Illinois'
p(i).FaceColor = 'r';
case 'Texas '
p(i).FaceColor = 'k';
case 'Ohio'
p(i).FaceColor = 'b';
case 'North Carolina'
p(i).FaceColor = 'c';
case 'Tennessee'
p(i).FaceColor = 'w';
end
end
I attached the table, this is a sample data because the original file is too large to attach and have more than 90 rows.
Really Thank you

Réponse acceptée

Ameer Hamza
Ameer Hamza le 12 Avr 2020
Try this
clf
f = figure();
ax = axes();
p = pie(ax, ones(1,5));
t = p(2:2:end);
p = p(1:2:end);
delete(t)
s = {'CC', 'ME', 'NU', 'BI', 'IA'};
for k=1:size(davar1, 1)
for i=1:numel(s)
switch davar1(k,:).([s{i} '_CHECK']) % I even tried insert (j) here and do it in the for loop but error says Index exceeds the number of array elements (2).
case 'New York'
p(i).FaceColor = 'g';
case 'California'
p(i).FaceColor = 'y';
case 'Illinois'
p(i).FaceColor = 'r';
case 'Texas '
p(i).FaceColor = 'k';
case 'Ohio'
p(i).FaceColor = 'b';
case 'North Carolina'
p(i).FaceColor = 'c';
case 'Tennessee'
p(i).FaceColor = 'w';
end
end
exportgraphics(ax, ['filename' num2str(k) '.png']);
end
  2 commentaires
BN
BN le 12 Avr 2020
This worked perfectly. Really Thank you. ??
Ameer Hamza
Ameer Hamza le 12 Avr 2020
Glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by