필터 지우기
필터 지우기

Z must be a matrix, not a scalar or vector.

조회 수: 1 (최근 30일)
AYMERIC BARBIN
AYMERIC BARBIN 2021년 2월 24일
댓글: AYMERIC BARBIN 2021년 3월 20일
Hello,
I would like to turn the figure drawn by this code:
t = linspace(-10,10,1000);
xt = exp(-t./10).*sin(5*t);
yt = exp(-t./10).*cos(5*t);
p = plot3(xt,yt,t);
Which gives this
To a figure with a filled surface, like one can do with surf, like so:
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z)
But,
surf(xt,yt,t);
gives this error: "Z must be a matrix, not a scalar or vector."
Thanks for your support

답변 (1개)

Just Manuel
Just Manuel 2021년 2월 24일
Well, have a look, what X, Y and Z are that allow you to make a surface.
Meshgrid gives you matrices for X and Y, thus Z is also a matrix (20 by 19 in your example).
You need to specify height values in t, so express it as a function of X and Y.
Cheers
Manuel
  댓글 수: 2
Just Manuel
Just Manuel 2021년 3월 2일
편집: Just Manuel 2021년 3월 2일
Try something along the lines of
[X,Y] = meshgrid(-2:0.2:2,-2:0.2:2);
[phi,r] = cart2pol(X,Y);
Z = -10.*log(r);
surf(X,Y,Z)
Which yields this:
Or even better: use the approach from this answer:
r = 0.5:0.1:2;
phi = 0:0.1:2*pi;
[R,PHI] = meshgrid(r,phi);
Z = -10.*log(R);
surf(R.*cos(PHI), R.*sin(PHI), Z)
Which yields this:
And please accept the answer, if it was of use to you.
Cheers
Manuel
AYMERIC BARBIN
AYMERIC BARBIN 2021년 3월 20일
Thanks !

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by