Applying a mask creates an odd artifact in the resulting map
Mostra commenti meno recenti
I am trying to limit a map to the data included within Denmark's EEZ. For example:

The EEZ shape file was downloaded from here: https://www.marineregions.org/gazetteer.php?p=details&id=5674
I want to include everything that is within the black lines. To do this, I am reading in the original mapping data, which is stored in a nc file, with 4D data (lat, lon, frequency, percentile). I extract it as so:
sample23 = 'path to nc file'
energy23 = ncread(sample23, '/AcousticData/energy');
lat = ncread(sample23, '/AcousticData/lat');
lon = ncread(sample23, '/AcousticData/lon');
prtc = ncread(sample23, '/AcousticData/percentile');
frq = ncread(sample23, '/AcousticData/frequency');
[num_lat, num_lon, num_percentile, num_freq, ~] = size(energy23);
% Create mask
eez=shaperead('./ShapeFiles/eez/eez.shp'); % From link above
[LonGrid, LatGrid] = meshgrid(lon, lat); % Note: lat is Y, lon is X
Y=eez.Y(~isnan(eez.Y))';
X=eez.X(~isnan(eez.X))';
inPoly = inpolygon(LonGrid, LatGrid,X,Y);
%apply EEZ mask
energy23sub=reshape(energy23, [],num_percentile*num_freq);
energy23sub(~inPoly, :)=nan;
energy23sub=reshape(energy23sub, size(energy23));
This has worked on other areas. However, when I apply this mask to these data, this is the resulting map that I get:

Where part of the data has been displaced/flipped to outside of the EEZ polygon. Can anyone help explain this? Or have any ideas on how to fix it?
I am sorry that I can not supply the data within the nc file.
3 Commenti
Mathieu NOE
il 28 Ott 2025
Modificato: Mathieu NOE
il 28 Ott 2025
hello
problem solved ?
I wanted to download the shape file but I had some hard time to find it in the link you provided
maybe you could share only the useful data as mat file(s) using the paperclip button
Emily T. Griffiths
il 30 Ott 2025
Mathieu NOE
il 30 Ott 2025
Good news !
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Geographic Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!