How to expand lat/lon vectors into arrays for scatter plot
Mostra commenti meno recenti
I am plotting a set of weather data over a Mercator projection. Most of the data arrives as 2D arrays containing lat and lon points, respectively:
lat 517x318 double array;
lon 517x318 double array;
ncData 517x318 double array containing ones and NaNs, used as a mask
I can scatter plot this data as follows:
latData = lat .* ncData;
lonData = lon .* ncData;
lonData(lonData == 0) = nan;
latData(latData == 0) = nan;
latLonData = scatter(lonData,latData,1,'green');
However, some of my data does not follow this pattern. In some cases, I get lat and lon files that are 1D vectors, not arrays. They appear to cover the range from max to min of the lat and lon coordinates in the ncData.
lat 517x1 vector
lon 318x1 vector
Is there a way to expand these two vectors into arrays, like the first instance, using interp2, say?
12 Commenti
Walter Roberson
il 7 Mar 2025
Walter Roberson
il 7 Mar 2025
Note that you could instead use
mask = ncData == 1;
latData = lat(mask);
lonData = lon(mask);
scatter(lonData, latData, 1, 'green');
Walter Roberson
il 7 Mar 2025
lonData = lon .* ncData;
lonData(lonData == 0)
Your ncData is documented as being 1's and NaN. Multiplying lon by that gives lon in places and NaN in other places. Checking whether the result is equal to 0 is checking for original locations that are 0 where the mask is 1.
I have to wonder whether this is correct code. Are you truely wanting to zap places where lon was 0? Or are you being inconsistent on "ones and NaNs" and really the ncData is ones and zeros ?
Cris LaPierre
il 7 Mar 2025
Do the 1D vectors contain the same number of elements? If yes, how are they organized?
Since you are using scatter, there is no need to make your data 2D. You might be able to use reshape
% reshape
lat = reshape(lat,size(ncData));
or just the colon operator (but not both simultaneously).
% colon operatore
latData = lat .* ncData(:)
dpb
il 7 Mar 2025
The unanswered Q? is whether these are actually the lat, lon coordinates or the observations at an assumed lat, lon location based on other instances?
If the former, then where are the observations to go with the coordinates?
Walter Roberson
il 7 Mar 2025
mask = ncData == 1;
[LatG, LonG] = ndgrid(lat, lon);
latData = LatG(mask);
lonData = LonG(mask);
Walter Roberson
il 7 Mar 2025
Use the ndgrid() solution that I posted.
Kurt
il 7 Mar 2025
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Resampling Techniques 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!