Matlab Error (Z must be a matrix, not a scalar or vector.)?

122 ビュー (過去 30 日間)
GURPREET
GURPREET 2012 年 7 月 27 日
コメント済み: Kolenchenko 2024 年 3 月 5 日
Hello
I was trying to plot using the following code but i get this error. Can someone help me please? Thank You
x = -2.5:.1:2.5;
y = -2.5:.1:2.5;
[X,Y] = meshgrid(x,y);
z = 2*sin(x.*y);
mesh(x,y,z)
grid on
hold on
Error using mesh (line 76) Z must be a matrix, not a scalar or vector.

採用された回答

George Papazafeiropoulos
George Papazafeiropoulos 2012 年 7 月 27 日
編集済み: George Papazafeiropoulos 2012 年 7 月 29 日
Is this what you want?
x = -2.5:.1:2.5;
y = -2.5:.1:2.5;
[X,Y] = meshgrid(x,y);
Z = 2*sin(X.*Y);
mesh(X,Y,Z)
grid on
hold on
George Papazafeiropoulos
  3 件のコメント
Miro
Miro 2012 年 7 月 27 日
lol you stole my reputation :)
Kolenchenko
Kolenchenko 2024 年 3 月 5 日
THNK U

サインインしてコメントする。

その他の回答 (2 件)

Miro
Miro 2012 年 7 月 27 日
編集済み: Miro 2012 年 7 月 27 日
ah you mixed up the capitals i guess. use ur meshgrid for your z like
z = 2*sin(X.*Y);
mesh(X,Y,z)

shahariar Ryehan
shahariar Ryehan 2022 年 6 月 12 日
編集済み: shahariar Ryehan 2022 年 6 月 12 日
I got the same error. Please help.
%variable declare
syms x;
syms t;
%putting the value
a=1;
b=-2;
c=-1;
alpha=1;
y=0;
%vartheta equation
vartheta = @(x, t)((a/alpha)*x.^alpha)+((b/alpha)*y^alpha)+c*t;
%delta
delta=-(2*c)/(b*a^2);
%mesh plot
x = -3:.1:3;
y = -3:.1:3;
[X,Y] = meshgrid(x,t);
%main function
Z=@(vartheta,delta)(-(2*(c^2)*((tanh(sqrt(-delta).*vartheta)).^2))/(b*delta*a^3));
mesh(X,Y,Z)
grid on
hold on
Result:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Error in M3_1_29_3 (line 30)
surf(v, 'edgecolor', 'none')

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by