How do I replace NaN values in contourf with another plot?
Afficher commentaires plus anciens
I am using contourf to plot salinity over a large region. Data only shows over ocean, so I was hoping to show an outline of the shoreline where NaN values appear on the contour. I've created a representative example in the following code:
X=rand(30,60);
X(10:25,10:30) = NaN;
figure();
subplot(2,1,1)
load coast;
lat2=[nan;lat;nan; lat];
long2=[nan;long; nan; long+360];
plot(long2,lat2,'k','linewidth',1)
axis([260 320 0 30]);
subplot(2,1,2)
contourf(X)
This example creates two subplots: the first shows the shorelines, the second shows contours with a hole (due to NaN values). I want to create one plot that shows the filled contours on top with the shorelines peaking through the hole.
I have tried making the NaN values transparent, but wasn't getting anywhere. Any help would be greatly appreciated!
2 commentaires
Star Strider
le 14 Oct 2016
Are you going to share ‘coast’, ‘lat’ and ‘lon’ with us?
Does this require the Mapping Toolbox? If so, please add that in the Product Tags.
Also, your axis call is perplexing, because ‘0’ and ‘30’ as integers can be represented exactly in binary form. No rounding is necessary.
Jonathan Whiting
le 17 Oct 2016
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Vector Fields dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!