3D matrix - 2 D plot, how to make a plot ?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!