How to plot 2 surfaces in a same chart?
3 次查看(过去 30 天)
显示 更早的评论
Manoj Krishnan Srinivasan
2021-5-20
评论: Manoj Krishnan Srinivasan
2021-5-20
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.
0 个评论
采纳的回答
Sulaymon Eshkabilov
2021-5-20
编辑: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
2021-5-20
编辑: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 Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!