Find values in 3D matrix with given indices
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bianka Markovic
le 20 Juil 2021
Commenté : darova
le 25 Juil 2021
Hello everyone,
I'm trying to modify my matrix but I'm a little stuck. Maybe someone has an idea how it could be solved in a less complicated way :)
Basically, I have a 3D data set whereis the first two dimension represent coordinates, longitude and latitude and the third one is the time. The data is given for a set of coordinates in a range where longitude is from -180:180 and the latitude from 20:90. Now I want to change the data so it is not given for all coordinates but just section where the latitude is from 77:81 and the longitude is 0 with +-1 entry in the matrix. In the end my data should have the dimensions 5x3x48.
I tried to do it in a way that I find the indexes where in the grid data these values take place, but i don't know how do i search and define my data vector with these given indices.
Maybe someone has an Idea, I would really appreciate it.
Thank you for your time :)
Bianka
%3D data
data=rand(71,361,48);
%Longitude and latitude data
lon_oras=(-180:180);
lat_oras=(20:90);
%define longitude section
lon=find(lon_oras==0);
%for more robustness
po=lon+1;
ne=lon-1;
%index fof longitude
idx_lon=[ne lon po];
%define latitude section
lat_range=77:81;
%find the index where the matrix take the numbers written in lat_range
idx_lat = find(lat_oras>=min(lat_range) & lat_oras<=max(lat_range));
0 commentaires
Réponse acceptée
Scott MacKenzie
le 20 Juil 2021
Modifié(e) : Scott MacKenzie
le 20 Juil 2021
Unless I'm missing something, this is just a simple matter of finding the indices corresponding to the latitude 77:81 elements and the longitude -1:1 elements. Try this:
data=rand(71,361,48); % lat (20:90), long (-180:180), time
% find indices to extract subset of data
latIdx = (77:81) - 19; % remap so 20 is 1, 21 is 2, and so on
lonIdx = (-1:1) + 181; % remap so -180 is 1, -179 is 2, and so on
datanew = data(latIdx,lonIdx,:);
whos
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!