Plot 2D surf from 3 columns (X, Y, Data)

89 vues (au cours des 30 derniers jours)
Vittorio Bonino
Vittorio Bonino le 29 Juil 2022
Commenté : Star Strider le 29 Juil 2022
Hi,
I have data disposed in the following way:
The first column rapresents the x coordinates, the second column rapresents the y coordinates and the 3rd column contains the data value at the (x, y) coords.
I can't use the function surf since it required that the 3rd column in disposed as a matrix where every index represents the coorinate.
So I'm looking for a way to convert my 3 columns in a matrix with my data, or plot directly the surface using a function that accepts that format.
Thank you!

Réponses (2)

Alan Stevens
Alan Stevens le 29 Juil 2022
Modifié(e) : Alan Stevens le 29 Juil 2022
plot3 will plot your points as a line (or series of points).
To get a surface, set up regular coordinates over the appropriate range for cp12x and cp12y, then use meshgrid to get a matrix, then interp2 to interpolate to find appropriate values of your magnetic field at those mesh points.
Then use surf.

Star Strider
Star Strider le 29 Juil 2022
Modifié(e) : Star Strider le 29 Juil 2022
Try something like this —
Tmag = readtable('FileName', 'VariableNamingRule','preserve');
x = Tmag{:,1};
y = Tmag{:,2};
z = Tmag{:,3};
L = size(Tmag,1);
xv = linspace(min(x), max(x), L);
yv = linspace(min(y), max(y), L);
[X,Y] = ndgrid(xv, yv);
Z = griddata(x, y, z, X, Y);
figure
surf(X, Y, Z)
grid on
Also consider adding:
shading('interp')
if the grid points are too dense.
.
.
  2 commentaires
Vittorio Bonino
Vittorio Bonino le 29 Juil 2022
Modifié(e) : Vittorio Bonino le 29 Juil 2022
Thank you for the answer, but it creates a 3D surf and not a 2D:
I need to realize a sort of color map. The final result should appear like this:
Star Strider
Star Strider le 29 Juil 2022
After the surf call, add:
shading('interp')
view(0,90)
That should work.
.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by