Find values in 3D matrix with given indices

4 visualizaciones (últimos 30 días)
Bianka Markovic
Bianka Markovic el 20 de Jul. de 2021
Comentada: darova el 25 de Jul. de 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));

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 20 de Jul. de 2021
Editada: Scott MacKenzie el 20 de Jul. de 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
Name Size Bytes Class Attributes data 71x361x48 9842304 double datanew 5x3x48 5760 double latIdx 1x5 40 double lonIdx 1x3 24 double
  2 comentarios
Bianka Markovic
Bianka Markovic el 23 de Jul. de 2021
thank you very much sir! It works now
darova
darova el 25 de Jul. de 2021

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by