netcdf files in a predefined domain

Hello,
I am trying to read multiple netcdf4 files in a predefined area (lat and lon). I want values OUTSIDE my predefined area to be equal to '-99' but below code changes all the values to -99.
NOTE: in the below code lat_edge and lon_edge are lat and lon values from first satellite and sub_lat and sub_lon are lat and lon values from second satellite. I'm doing collocation first.
lat_edge=double([min(lat(:)) max(lat(:))]);
lon_edge=double([min(lon(:)) max(lon(:))]);
index_out_edge=find(sub_lat(:)<=lat_edge(1) | sub_lat(:)>=lat_edge(2) | sub_lon(:)<=lon_edge(1) | sub_lon(:)>=lon_edge(2));
CLTT_temp = ncread(files{i},'CLTT');
CLTT_temp_FINAL=CLTT_temp(min(row):max(row),min(col):max(col)); %min and max row col are lat lon indices from second satellite.
CLTT_temp_FINAL(index_out_edge)=-99;
kindly tell me what I'm missing in my code.
thank you.

댓글 수: 6

What shows up for
nnz(sub_lat(:)>lat_edge(1) & sub_lat(:)<lat_edge(2) & sub_lon(:)>lon_edge(1) & sub_lon(:)<lon_edge(2))
If this shows up as 0 then every point was determined to be out of bounds.
IMC
IMC 2021년 3월 11일
Thank you.
Yeah it's 0.
What are
lat_edge
lon_edge
min(sub_lat(:)), max(sub_lat(:))
min(sub_lon(:)), max(sub_lon(:))
IMC
IMC 2021년 3월 14일
lat_edge = 12.3334 33.2646
lon_edge = 125.8553 152.3933
min(sub_lat(:)) = 15
max(sub_lat(:)) = 55
min(sub_lon(:)) = 80
max(sub_lon(:)) = 140
It looks like the distribution of your values might be biased. I suggest investigating with something like
lat_edge = double([min(lat(:)) max(lat(:))]);
lon_edge = double([min(lon(:)) max(lon(:))]);
fill(lon_edge([1 2 2 1]), lat_edge([1 1 2 2]), [.5 .5 .5]);
hold on
scatter(sub_lon, sub_lat, [], 'r')
hold off
xlim auto
ylim auto
The red marks that show up in the mid-gray background are the ones that should be located by index_out_edge. My suspicion is that you will find all your marks are outside the rectangle.
IMC
IMC 2021년 3월 16일
Thank you

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

답변 (1개)

KSSV
KSSV 2021년 3월 11일

0 개 추천

Something like this should work:
index_out_edge = ~(((sub_lat(:)<=lat_edge(1) | sub_lat(:)>=lat_edge(2)) && (sub_lon(:)<=lon_edge(1) | sub_lon(:)>=lon_edge(2))));

질문:

IMC
2021년 3월 11일

댓글:

IMC
2021년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by