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
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
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!