How to plot 2 surfaces in a same chart?

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Sulaymon Eshkabilov
Sulaymon Eshkabilov il 20 Mag 2021
Modificato: Sulaymon Eshkabilov il 20 Mag 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 Commenti
Sulaymon Eshkabilov
Sulaymon Eshkabilov il 20 Mag 2021
Modificato: Sulaymon Eshkabilov il 20 Mag 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.
Manoj Krishnan Srinivasan
Manoj Krishnan Srinivasan il 20 Mag 2021
It works now, thank you sir.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by