How to plot each matrix in a cell in 3d plot ?

Let's say: Cell A with size of 1x100 cell:
A={1x100} cell
And the size each matrix in the cell A is like this:
{A}= {[A1] [A2] [A3] [A4] [A5]......... [A100] }
{A}= {[5000x3 double] [1000x3 double]......... [2222x3 double] }
Where the structure of matrix Ai is coordinate (x,y,z)
Example:
[A1]= [2 1 1 ------> coordinate of point 1
3 2 4
5 2 6
........
........
7 9 1] ------> coordinate of point 5000
How to plot all matrix (coordinate) of cell A in 1 figure in 3d graph? (if possible, please help me plot 1 matrix with 1 color)

 Réponse acceptée

Akira Agata
Akira Agata le 6 Sep 2017
I don't think it's better to plot 100 lines in one graph... But I believe the following code would be what you want to do. I hope this sample code can help you!
% Make 100 colors
color = jet(100);
% Sample data (1x100 cell array)
A = cell(1,100);
for kk = 1:numel(A)
z = 10*rand()+(0:pi/50:10*rand()*pi)';
x = 10*rand()*sin(z);
y = 10*rand()*cos(z);
A{kk} = [x,y,z];
end
% Plot them in one figure with different color
figure
hold on;
for kk = 1:numel(A)
plot3(A{kk}(:,1),A{kk}(:,2),A{kk}(:,3),...
'Color',color(kk,:));
end
view(3);

5 commentaires

KALYAN ACHARJYA
KALYAN ACHARJYA le 6 Sep 2017
ha ha
ha ha le 6 Sep 2017
Modifié(e) : ha ha le 7 Sep 2017
actually, I wanna plot coordinate (x y z) of "each point" in all matrices from cell A (not plot line).
In your code, you use syntax" plot3" for plot 3d Line. But i wanna plot point, point only (I must use syntax "scatter3"). But I don't know how to make 1 color for 1 matrix by using "scatter3"). Can you help me?
I have just modified the code. It generates A={1xN} cell array and plots each point. To simplify, N was set to 33 in the following code.
N = 33;
% Make N colors
color = jet(N);
% Sample data (1xN cell array)
A = cell(1,N);
for kk = 1:numel(A)
z = 20*rand()+(0:pi/8:10*rand()*pi)';
x = 20*rand()+2*rand()*sin(z);
y = 20*rand()+2*rand()*cos(z);
A{kk} = [x,y,z];
end
% Plot them in one figure with different color
figure
hold on;
for kk = 1:numel(A)
plot3(A{kk}(:,1),A{kk}(:,2),A{kk}(:,3),...
'.','Color',color(kk,:));
end
grid on;
view(3);
ha ha
ha ha le 8 Sep 2017
Modifié(e) : ha ha le 8 Sep 2017
Thank so much,@ Akira Agata
One more question? If i want to use "color map" to show the color corresponding with the number of matrices, how can i do that? (e,g. i have 10 matrices (A1, A2, A3,..., A10), so the color bar will show 10 color , and also show 10 number from 1 to 10 corresponding with 10 colors)
Please see illustrated photo
Akira Agata
Akira Agata le 10 Sep 2017
How about adding a "legend", instead of a "color bar," to the figure? When you add legend('show'); to the code, the output figure becomes like this.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2 次元および 3 次元プロット dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!