How to plot 2 surfaces in a same chart?

3 次查看(过去 30 天)
I need to plot 2 surface in a same chart, but facing errors when plotting the first surface itself. So yet to try how to plot 2 surface in the same chart.
I am trying to plot a surface as below:
a=readtable(file.csv);
X=a(:,1);
Y=a(:,2);
Z=a(:,3);
surf(X,Y,Z)
I am facing the below errors:
Error using tabular/length (line 212)
Undefined function 'LENGTH' for input arguments of type 'table'. Use the HEIGHT,
WIDTH, or SIZE functions instead.
Error in surf (line 60)
hasParentArg = strncmpi(args{i}, 'parent', length(args{i}));
Error in Plot_forces (line 7)
surf(X,Y,Z)
Please guide me as I am new to matlab.

采纳的回答

Sulaymon Eshkabilov
编辑:Sulaymon Eshkabilov 2021-5-20
% To create a surface you need 2D data for Z
a=readtable(file.csv);
X=a(:,1);
Y=a(:,2);
[x, y] = meshgrid(X, Y);
Z = .... % some f(x, y) math expression
% OR
z= meshgrid(Z);
surf(x,y,z)
  5 个评论
Sulaymon Eshkabilov
编辑:Sulaymon Eshkabilov 2021-5-20
Note that while importing your data from *.csv, your imported data will be in a table variable format and thus, you'd need to convert it into matrix format. Therefore, you should use the conversion first:
X = table2array(a(:,1));
Y = table2array(a(:,2));
Z = table2array(a(:,3));
%%
[x,y] = meshgrid(X',Y');
z = meshgrid(Z');
surf(x,y,z)
One more thing,note that Z and z are not the same variable names.
In your case, it make more sense to plot your 3 data arrays using plot3(X, Y, Z)
Good luck.

请先登录,再进行评论。

更多回答(0 个)

类别

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