How do I select data based on multiple indexes?

12 次查看(过去 30 天)
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 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by