3D matrix - 2 D plot, how to make a plot ?

4 次查看(过去 30 天)
N
N 2014-2-18
评论: N 2014-2-18
I have a 3D 3*3 matrix, that I had in a loop and it got repeated 202 times. The matrix consists of x,y,z.I would like to make a 2D-plot of all the x, y and z against the sample numbers (202). So just three lines on the plot in the end. When I do the plot function I now get hundred of lines, I don't want that. Can anybody help ?
for i= [1:202];
origin2=(LE(:,i)+ME(:,i))/2;
Y2=(FH(:,i)-origin2)/norm(FH(:,i)-origin2);
ztemp2=(FH(:,i)-ME(:,i))/norm(FH(:,i)-ME(:,i));
x2=cross(Y2,ztemp2);
X2=x2/norm(x2);
z2=cross(X2,Y2);
Z2=z2/norm(z2);
R2(:,:,i)=[X2 Y2 Z2];
midpoint=(LM(:,i)+MM(:,i))/2;
mid=(MLP(:,i)+MMP(:,i))/2;
Y3=(mid-midpoint)/norm(mid-midpoint);
ztemp3=(LM(:,i)-MM(:,i))/norm(LM(:,i)-MM(:,i));
x3=cross(Y3,ztemp3);
X3=x3/norm(x3);
z3=cross(X3,Y3);
Z3=z3/norm(z3);
R3(:,:,i)=[X3 Y3 Z3];
relor(:,:,i)=R2(:,:,i)\R3(:,:,i);
hold on
t=1:202;
plot(t,relor(1,1,:))
hold off
end

回答(2 个)

David Sanchez
David Sanchez 2014-2-18
Plot the data after the finishing the loop.
plot(t,x,t,y,t,z)
Just add your x,y,z data. Your code is a bit confusing.
  3 个评论
David Sanchez
David Sanchez 2014-2-18
relor(:,:,1) is a 2D matrix, who are x,y and z?
N
N 2014-2-18
oh I thought it was a 3D matrix, they told me it was.. So I have an R2(:,:,i)=[X2 Y2 Z2] and an R3 that is build up the same way.From this I calculate the relor. And this I then want to put in a plot, so the first three datapoints are X

请先登录,再进行评论。


Iain
Iain 2014-2-18
Have you tried:
plot(relor(:,:,1)') %?
If you do it explicitly, you'll get exactly what you want:
plot(relor(:,1,1),'r') % 1st column in red.
hold on % to stop overwriting...
plot(relor(:,2,1),'k') % 2nd column in black
plot(relor(:,3,1),'gx') % 3rd column in green crosses.
  1 个评论
N
N 2014-2-18
I get a blank plot when I use this.. Should I place somehing before it or place it on a specific place ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by