Error using plot3 Vectors must be the same length.

7 次查看(过去 30 天)
This is the code I am working with and it shows error, Whats the problem and what can be done to solve it?
t = linspace(-100*pi, 100*pi); %define the range you are plotting over
x = (t-2)/(t+2);
y = sin(t);
z = log(9-t.^2);
plot3(x, y, z);
axis equal
  1 个评论
Pawan Sharma
Pawan Sharma 2020-9-28
Hello Ajay,
You are getting the error as x,y,z are not of the same length. x is a single element vector. if you want to do (t-2)/(t+2) to every elememt use (t-2)./(t+2) The code goes liked this
t = linspace(-100*pi, 100*pi); %define the range you are plotting over
x = (t-2)./(t+2);
y = sin(t);
z = log(9-t.^2);
plot3(x, y, z);
axis equal

请先登录,再进行评论。

回答(1 个)

KSSV
KSSV 2020-9-28
Read about element by element operations.
t = linspace(-100*pi, 100*pi); %define the range you are plotting over
x = (t-2)./(t+2); % <----- element by element divison
y = sin(t);
z = log(9-t.^2);
plot3(x, y, z);
axis equal

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by