how to crop a 3d data using lat , long and save the cropped file?

hello everyone
i am trying to crop a 3d data and save the cropped data. i tried a simple code for cropping
RF6=RF(60:110,5:45,:);
but it gave me the error as
Index in position 1 exceeds array bounds (must not exceed 34).
how do i crop the data?

Answers (1)

The array does not have 110 rows -- it has only 34. Are you sure you're indexing by RF(row, columns, slice) and not by RF(x, y, slice)? Because y is row, it comes first, like RF(y, x, slice). Otherwise just read to the end with
RF6 = RF(60 : end, 5 : end, :);
but it will have to have at least 60 rows and 5 columns.

8 Comments

i tried using this code but it didnt work. i have attached the data here as well
https://drive.google.com/file/d/1jyPTrJQgcW2zP5cEV5dDkMILPe8XGTUV/view?usp=sharing
What does this show in the command window:
[rows, columns, slices] = size(RF) % No semicolon!
rows=34, columns=450 and slices=4173
OK, so if the rows only go from 1 to 34, how/why are you hoping to go from 60 to 110??? These indexes are way more than the number of rows your array has! Explain the rationale for that.
60 to 110 is the longitude extension of my study area. the data shows the path of a satellite (Sentinel 5P). from this i need crop my study area.how do i do that?
OK but those are not row index numbers, those are longitudes. In your array what longitude is at row 1? Is it 0 or 180 or something else? What longitude is at row 34? Is it 110 or 180 or 360 or something else?
in the longitude array in row 1 the value is -72.2852 in row 34 it is -72.2385. how do i crop my area from these values?
I'm not sure what that means. Crop what? You just have to know what row or column is what value. If it's linear you can find out what longitude is in each row by doing this:
coefficients = polyfit([1, 34], [-72.2852, -72.2385], 1);
longitudes = polyval(coefficients, 1:34);
Now longitudes(someRow) will give you a number around 72 for whatever index you specify for someRow. If that helps, maybe you can click the "Accept this answer" link.

Sign in to comment.

Tags

Asked:

on 22 Nov 2021

Commented:

on 24 Nov 2021

Community Treasure Hunt

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

Start Hunting!