MATLAB: I need to create a 3d plot. I have created a 5×24 matrix called Mneg that contains all the info needed.I need to plot the 3rd row(as z) vs the 1st (as x) and 2nd row (as y). How to do this? Thanks in advance! Cheers

3d plotplot3 from mxn matrix

Beam.sigmaZ = 731;% um
Beam.espread = 0.2; % percent
Beam.energy = 0.116; % GeV
N = 10000;
Z = Beam.sigmaZ * randn(N,1);
E = Beam.energy * (1 + Beam.espread * randn(N,1) / 100);
f_S=3e+9; % Hz
lamda_S = (3e+8)/f_S;% m
kRF_S = 2*pi/lamda_S;% 1/m
kRF_X=4*kRF_S;
L=[];
E0=0.20;
phi_S=[10:10:89];
phi_X= [120:10:199];
for phi=phi_S(1):(phi_S(2)-phi_S(1)):phi_S(length(phi_S))
eV_S = (E0-Beam.energy)/cos(phi);
R65_S = -(kRF_S*eV_S*sin(phi))/E0;
for phix=phi_X(1):(phi_X(2)-phi_X(1)):phi_X(length(phi_X))
eV_X = -eV_S*cos(phi)/16*cos(phix);
R65_X = -(kRF_X*eV_X*sin(phix))/E0;
h=R65_S+R65_X;
R56= -1/h;
L=[L,[phi;phix;R56;eV_S;eV_X]];
end
end
[r,c]=find(L(3,:) < 0);
Mneg=L(:,c);

Best Answer

  • The plot3 function will do what you want:
    figure(1)
    plot3(Mneg(1,:), Mneg(2,:), Mneg(3,:))
    grid on
    xlabel('X')
    ylabel('Y')
    zlabel('Z')