Error using plot3 - Vectors must be the same lengths.

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?

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 30 日
編集済み: Azzi Abdelmalek 2014 年 4 月 30 日

0 投票

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;

1 件のコメント

Aiman
Aiman 2014 年 4 月 30 日
thanks! it solved my prob

サインインしてコメントする。

カテゴリ

質問済み:

2014 年 4 月 30 日

コメント済み:

2014 年 4 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by