How do I select data based on multiple indexes?

조회 수: 23 (최근 30일)
Shayma Al Ali
Shayma Al Ali . 2021년 10월 1일
답변: Kelly Kearney . 2021년 10월 1일
I have a data set called 'total_backscatternight'. I have three flags, 'water_data','Perp_saturationdata','Par_saturationdata', where I would like to select data from 'total_backscatternight' based on those three flags. However, once I select data after one flag, I get the error that 'Index exceeds the number of array elements (43696)'. How do I select the data based on all three flags?
My code:
%find data in ocean
water_data=find(landwatermask==7 | landwatermask==0);
Perp_saturationdata=find(PerpSurface_saturationflag==0);
Par_saturationdata=find(ParSurface_saturationflag==0);
t_backscatternight=total_backscatternight(:,562);
p_backscatternight=perp_backscatternight(:,562);
t_backscatternight=t_backscatternight(Perp_saturationdata);
p_backscatternight=p_backscatternight(Perp_saturationdata);
t_backscatternight=t_backscatternight(Par_saturationdata);
p_backscatternight=p_backscatternight(Par_saturationdata);
t_backscatternight=t_backscatternight(water_data);
p_backscatternight=p_backscatternight(water_data);
The files have been uploaded in different files.

답변 (1개)

Kelly Kearney
Kelly Kearney 2021년 10월 1일
Assuming that the landwatermask, PerpSurface_saturationflag, and ParSurface_saturationflag matrices are all the same size, and they have the same number of elements as rows in total_backscatternight and perp_backscatternight:
mask = (landwatermask == 7 | landwatermask == 0) & ...
PerpSurface_saturationflag==0 & ...
ParSurface_saturationflag==0;
t_backscatternight = total_backscatternight(mask(:),562);
p_backscatternight = perp_backscatternight(mask(:),562);

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by