Error using mesh Z must be a matrix, not a scalar or vector. Error in untitled6 (line 5) mesh(W,Y,Z)

1 visualización (últimos 30 días)
Hi, I am trying to commute this 3D plot, however I am receiving an error.
w = 200:50:450;
y=180;
[W,Y] = meshgrid(w,y);
Z= 64.0189+1.4629*W-2.626*Y-0.0012*W.^2+0.0098*W.*Y+0.0082*Y.^2
mesh(W,Y,Z)
Error using mesh
Z must be a matrix, not a scalar or vector.
Error in untitled6 (line 5)
mesh(W,Y,Z)

Respuesta aceptada

KSSV
KSSV el 26 de Jul. de 2022
As you have given single value of Z, it would be a line.
w = 200:50:450;
y=repmat(180,1,length(w));
[W,Y] = meshgrid(w,y);
Z= 64.0189+1.4629*W-2.626*Y-0.0012*W.^2+0.0098*W.*Y+0.0082*Y.^2
Z = 6×6
1.0e+03 * 0.4544 0.5887 0.7171 0.8394 0.9558 1.0661 0.4544 0.5887 0.7171 0.8394 0.9558 1.0661 0.4544 0.5887 0.7171 0.8394 0.9558 1.0661 0.4544 0.5887 0.7171 0.8394 0.9558 1.0661 0.4544 0.5887 0.7171 0.8394 0.9558 1.0661 0.4544 0.5887 0.7171 0.8394 0.9558 1.0661
mesh(W,Y,Z)
  6 comentarios
KSSV
KSSV el 26 de Jul. de 2022
Man for this you need to define, w and y as vectors and then use meshgrid
w = 200:50:450;
y=200:50:500;
[W,Y] = meshgrid(w,y);
Z= 64.0189+1.4629*W-2.626*Y-0.0012*W.^2+0.0098*W.*Y+0.0082*Y.^2
Z = 7×6
1.0e+03 * 0.5034 0.6475 0.7857 0.9178 1.0440 1.1641 0.6546 0.8232 0.9859 1.1425 1.2932 1.4378 0.8468 1.0399 1.2271 1.4082 1.5834 1.7525 1.0800 1.2976 1.5093 1.7149 1.9146 2.1082 1.3542 1.5963 1.8325 2.0626 2.2868 2.5049 1.6694 1.9360 2.1967 2.4513 2.7000 2.9426 2.0256 2.3167 2.6019 2.8810 3.1542 3.4213
surf(W,Y,Z)

Iniciar sesión para comentar.

Más respuestas (1)

Chunru
Chunru el 26 de Jul. de 2022
w = 200:50:450;
y=120:30:240;
[W,Y] = meshgrid(w,y);
Z= 64.0189+1.4629*W-2.626*Y-0.0012*W.^2+0.0098*W.*Y+0.0082*Y.^2;
whos
Name Size Bytes Class Attributes W 5x6 240 double Y 5x6 240 double Z 5x6 240 double cmdout 1x33 66 char w 1x6 48 double y 1x5 40 double
mesh(W,Y,Z)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by