Plot a cell array containing n matrices on same graph but with different color for each matrix.
古いコメントを表示
I have a cell array with which contains n matrices. I want to plot the cell array with each matrix plotted on the same graph. Each matrix line should be plotted with a different color.
2 件のコメント
Akira Agata
2017 年 8 月 12 日
Question for clarification. You mean, your cell array is 1-by-n (or n-by-1), and each cell contains numeric array? If so, what is the size of each numeric array?
Anuj Prajapati
2017 年 8 月 16 日
採用された回答
その他の回答 (2 件)
Akira Agata
2017 年 8 月 17 日
Here is another way. By using cellfun, you don't need to use for-loop.
% Sample 10-by-1 cell
C = cell(10,1);
for kk = 1:10
C{kk} = rand(randi(20),1);
end
% Plot
figure
hold on;
cellfun(@plot,C);
Cemil Közkurt
2017 年 8 月 13 日
編集済み: Cemil Közkurt
2017 年 8 月 13 日
a=cell(2,2);
a{1,1}=[1:10;rand(1,10)];
a{1,2}=[1:5;rand(1,5)];
a{2,1}=[1:8;rand(1,8)];
a{2,2}=[1:3;rand(1,3)];
s=size(a);
for n=1:s(1)
for m=1:s(2)
plot(a{n,m}(1,:),a{n,m}(2,:))
hold on
end
end
5 件のコメント
Walter Roberson
2017 年 8 月 16 日
Anuj Prajapati comments to Cemil:
This plots with same color for each matrix.
Walter Roberson
2017 年 8 月 16 日
Anuj Prajapati: In R2014b and later, this plots with a different color for each matrix.
Cemil Közkurt
2017 年 8 月 20 日
a=cell(2,2);
a{1,1}=[1:10;rand(1,10)];
a{1,2}=[1:5;rand(1,5)];
a{2,1}=[1:8;rand(1,8)];
a{2,2}=[1:3;rand(1,3)];
s=size(a);
for n=1:s(1)
for m=1:s(2)
plot(a{n,m}(1,:),a{n,m}(2,:))
hold on
end
end

am i a color blind?
Walter Roberson
2017 年 8 月 20 日
That appears to be four distinct colors to me.
Anuj Prajapati
2017 年 8 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Surface Style についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!