# Find values in 3D matrix with given indices

조회 수: 1(최근 30일)
Bianka Markovic 2021년 7월 20일
댓글: darova 2021년 7월 25일
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));

댓글을 달려면 로그인하십시오.

### 답변(1개)

Scott MacKenzie 2021년 7월 20일
편집: Scott MacKenzie 2021년 7월 20일
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표시숨기기 이전 댓글 수: 1
darova 2021년 7월 25일

댓글을 달려면 로그인하십시오.

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by