Plot multiple separate figures
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
BN
el 12 de Abr. de 2020
Comentada: Ameer Hamza
el 12 de Abr. de 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
0 comentarios
Respuesta aceptada
Ameer Hamza
el 12 de Abr. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!