x = linspace(-10, 10, 50);
y = linspace(-10, 10, 50);
[X,Y] = meshgrid(x,y);
Z = X.^2. * Y;
figure(1)
surf(X, Y, Z)
Don't know why the output just shows a flat surface

답변 (1개)

Voss
Voss 2023년 2월 17일

0 개 추천

You have an extra space between "." and "*"
Z = X.^2. * Y;
% ^ space breaks up the .* operator
That causes Z to be the matrix product (*) of X.^2. and Y, which happens to result in a matrix containing one unique value very close to 0:
x = linspace(-10, 10, 50);
y = linspace(-10, 10, 50);
[X,Y] = meshgrid(x,y);
Z = X.^2. * Y;
unique(Z)
ans = -5.6843e-13
Remove the extra space, and you'll get Z to be the element-wise product (.*) of X.^2 and Y, as intended:
Z = X.^2.* Y;
surf(X, Y, Z)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2023년 2월 17일

답변:

2023년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by