How do I select data based on multiple indexes?
6 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Kelly Kearney
on 1 Oct 2021
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);
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!