How to plot 2 surfaces in a same chart?
3 views (last 30 days)
Show older comments
Manoj Krishnan Srinivasan
on 20 May 2021
Commented: Manoj Krishnan Srinivasan
on 20 May 2021
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 Comments
Accepted Answer
Sulaymon Eshkabilov
on 20 May 2021
Edited: Sulaymon Eshkabilov
on 20 May 2021
% 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 Comments
Sulaymon Eshkabilov
on 20 May 2021
Edited: Sulaymon Eshkabilov
on 20 May 2021
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.
More Answers (0)
See Also
Categories
Find more on Surface and Mesh 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!