Plot multiple separate figures

2 ビュー (過去 30 日間)
BN
BN 2020 年 4 月 12 日
コメント済み: Ameer Hamza 2020 年 4 月 12 日
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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 12 日
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 件のコメント
BN
BN 2020 年 4 月 12 日
This worked perfectly. Really Thank you. ??
Ameer Hamza
Ameer Hamza 2020 年 4 月 12 日
Glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by