MATLAB: Find the index of cell array containing numeric values

cell arrayindex

Hi!I have a cell array=YTLim, which contains at each cell the measurements of each for significant wave height Hs(numeric values).Each cell has 2920=365*8 or 2928=366*8 measurements,it depends on the year.So first cell has the values
YTLim{1}=[1,2,3,...,2920]
YTLim{2}=[2921,2922,2923,...,5840] etc
I have,also, a vector that contains the spot of some measurements. For example:
maxpos=[242;365;...;8555]
I need to find a way to take the index of the cell containing the vector's value…Is that possible?
I need something like that:
YS=[1;1;2;...;10;11;11]

Best Answer

Here is a miniature example that I believe does what you've asked for:
YTLim{1}=[1,2,3,4];
YTLim{2}=[5,6,7,8];
YTLim{3}=[9,10,11,12,13];
maxpos=[1,3,7,13];
c = cellfun(@(x)(ismember(maxpos,x)),YTLim,'UniformOutput',false);
[YS,~] = find(reshape([c{:}],numel(maxpos),[])')
I have to admit the code is compact and maybe a bit obscure. But if you take the time to examine each piece, I'm confident you can see what each individual command is doing.