I'm trying to plot to function but keep getting an error saying "Vectors must be the same length." how do I fix this

조회 수: 1 (최근 30일)
for w = [2,5,8]'
for t = (0:1:6)'
T = 0.15;
y = 1./(sqrt(1+(w*T).^2));
y1 = -atan(w*T);
plot(t,y,t,y1)
legend('input','output')
end
end
  댓글 수: 1
Torsten
Torsten 2022년 3월 9일
편집: Torsten 2022년 3월 9일
t has length 7, y and y1 both have length 3.
How do you intend to plot a vector with 3 elements against a vector with 7 elements ?
Before you answer again: How to fix this ?, first tell us what you want to plot against what.
Plotting y and y1 against t with
y = 1./(sqrt(1+(w*t).^2));
y1 = -atan(w*t);
only works if you use only one element of the w-vector, not three at a time.

댓글을 달려면 로그인하십시오.

답변 (1개)

David Hill
David Hill 2022년 3월 9일
편집: David Hill 2022년 3월 9일
Not sure what you are trying to do. There is no t in your questions, only a single variable w. Why the for-loops?
[w,t]=meshgrid([2 5 8],0:6);
y = 1./(sqrt(1+(w.*t).^2));
y1 = -atan(w.*t);
surf(t,w,y);
figure;
surf(t,w,y1);

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by