How do I select data based on multiple indexes?

18 vues (au cours des 30 derniers jours)
Shayma Al Ali
Shayma Al Ali le 1 Oct 2021
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.

Réponses (1)

Kelly Kearney
Kelly Kearney le 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);

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by