some meshgrid and matlab.chart.graphics errors

3 次查看(过去 30 天)
Hi. i wana draw my function of three variable. this is my code and i got those Errors. what shloud i do?
>> Q=[1 2 3;4 5 6;7 8 9];
>> S=[0;1;2];
>> u1=linspace(-10,10,20);
>> u2=linspace(-10,10,20);
>> u3=linspace(-10,10,20);
>> [U1,U2,U3]=meshgrid(u1,u2,u3);
>> L=1/2*(Q(1,1)*U1.^2+(Q(1,2)+Q(1,3)+Q(2,1)+Q(2,3)+Q(3,1)+Q(3,2))*U1.*U2.*U3+Q(2,2)*U2.^2+Q(3,3)*U3.^2)+S(1)*U1+S(2)*U2+S(3)*U3;
>> meshc(U1,U2,U3,L)
Error using matlab.graphics.chart.primitive.Surface/set
Value must be a vector or 2D array of numeric type
Error in matlab.graphics.chart.internal.ctorHelper (line 8)
set(obj, pvpairs{:});
Error in matlab.graphics.chart.primitive.Surface
Error in mesh (line 143)
hh = matlab.graphics.chart.primitive.Surface('XData',x,'YData',y,'ZData',z,'CData',c,...
Error in meshc (line 58)
hm = mesh(cax, x, y, z, c);

回答(2 个)

Steven Lord
Steven Lord 2020-12-5
Q=[1 2 3;4 5 6;7 8 9];
S=[0;1;2];
u1=linspace(-10,10,20);
u2=linspace(-10,10,20);
u3=linspace(-10,10,20);
[U1,U2,U3]=meshgrid(u1,u2,u3);
L=1/2*(Q(1,1)*U1.^2+(Q(1,2)+Q(1,3)+Q(2,1)+Q(2,3)+Q(3,1)+Q(3,2))*U1.*U2.*U3+Q(2,2)*U2.^2+Q(3,3)*U3.^2)+S(1)*U1+S(2)*U2+S(3)*U3;
whos U1 U2 U3 L
Name Size Bytes Class Attributes L 20x20x20 64000 double U1 20x20x20 64000 double U2 20x20x20 64000 double U3 20x20x20 64000 double
Does meshc accept 3-dimensional arrays as input? [Hint: it does not.] I think you probably want one of the volume visualization functions (https://www.mathworks.com/help/matlab/volume-visualization.html) instead.
  1 个评论
Hamid Reza N.D
Hamid Reza N.D 2020-12-5
meshc accepts 2-dimensional arrays. and gives me figure. but this time i have these errors how can i find that my meshc accepts 3-dimensional arrays as input?

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2020-12-5
编辑:Walter Roberson 2020-12-5
You cannot use meshc to draw a function with three independent variables and one dependent variable.
You also cannot use patch or surface for this purpose, at least not directly.
You could do a triangulation and a triangular mesh plot in which the dependent variable was represented by color https://www.mathworks.com/help/matlab/ref/trimesh.html
but with the grid being evenly spaced you are going to have trouble looking "into" the volume.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by