Effacer les filtres
Effacer les filtres

plot contour line of three variable ?

1 vue (au cours des 30 derniers jours)
Akim Mahmud
Akim Mahmud le 20 Déc 2017
Hi I have thistext file ( please see attached )with 3 columns ( lat, lon and depth ) I want to plot a contour map of the water depth as a function of lat and lon. I used the following code contour (lat,lon,depth) where I extracted lat, lon, and depth separately but I get this error "Z must be at least a 2x2 matrix."
any help ? thanks

Réponses (2)

Star Strider
Star Strider le 20 Déc 2017
Modifié(e) : Star Strider le 20 Déc 2017
If the file is very large, probably the easiest way to see if your data are gridded (such that the ‘x’ and ‘y’ values repeat in a specific, regular pattern) is to plot your vectors using the stem3 function. If they appear to be regularly-spaced, you can use the reshape function to form them into matrices. Then you can use your matrices with contour.
If they are not gridded, you will have to interpolate them to be gridded matrices. See the griddata (link) function and its friends to do that.
EDIT
If ‘M’ is your (Nx3) matrix:
x = linspace(min(M(:,1)), max(M(:,1)), size(M,1)+1);
y = linspace(min(M(:,2)), max(M(:,2)), size(M,1)+1);
[X,Y] = meshgrid(x, y);
Z = griddata(M(:,1), M(:,2), M(:,3), X, Y);
figure(1)
contourf(X, Y, Z)
axis equal
grid
Experiment to get the result you want.
  1 commentaire
Akim Mahmud
Akim Mahmud le 20 Déc 2017
I am not sure, if I follow you correctly. I am still new to matlab. I have attached a sample txt from the big txt file. I have used the stem2 function to see the data I am not sure how to use reshape function to from them into matrices. Any help would be appreciated

Connectez-vous pour commenter.


Harshana Rajakaruna
Harshana Rajakaruna le 15 Mar 2018
Thanks

Catégories

En savoir plus sur Contour 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!

Translated by