How to plot 2 surfaces in a same chart?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Manoj Krishnan Srinivasan
le 20 Mai 2021
Commenté : Manoj Krishnan Srinivasan
le 20 Mai 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 commentaires
Réponse acceptée
Sulaymon Eshkabilov
le 20 Mai 2021
Modifié(e) : Sulaymon Eshkabilov
le 20 Mai 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 commentaires
Sulaymon Eshkabilov
le 20 Mai 2021
Modifié(e) : Sulaymon Eshkabilov
le 20 Mai 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!