Error using plot3 - Vectors must be the same lengths.

1 view (last 30 days)
i had constructed a code to plot 3d graph between Electric Field and Magnetic Field
%Electric Field
AmpE = 4;
%Magnetic Field
AmpH = 2;
time = -1:0.01:1;
frequency = 97;
phase = 97;
phase_in_rad = degtorad(phase);
%Formula
E = AmpE*cos(2*pi*frequency*time+phase_in_rad);
H = AmpH*cos(2*pi*frequency*time+phase_in_rad);
end_limit=length(E);
x1 = E;
z1 = 1; end_limit;
y1 = zeros(1, end_limit);
y2 = H;
z2 = 1; end_limit;
x2 = zeros(1, end_limit);
plot3(z1,x1,y1);
hold on;
plot3(z2,x2,y2,'r');
hold off;
the problem is im getting error - "Vectors must be the same lengths".any ideas?

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 30 Apr 2014
Edited: Azzi Abdelmalek on 30 Apr 2014
In your code there is an error with z1 and z2
z1 = 1;end_limit;
it should be
z1 = 1: end_limit;
and
z2= 1: end_limit;

Community Treasure Hunt

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

Start Hunting!