some meshgrid and matlab.chart.graphics errors
Show older comments
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);
Answers (2)
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
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 Comment
Hamid Reza N.D
on 5 Dec 2020
Walter Roberson
on 5 Dec 2020
Edited: Walter Roberson
on 5 Dec 2020
0 votes
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.
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!