MATLAB: How to find index in cell array to start cumsum

cellcell arrayscellscumsumcumulative sumindexindexingsum

Hello, I have a cell array 'ddvaluecell'.
I would like to find the index of values in these cells which are > 0.5.
Then starts a cumsum for the next 5 indices or stop early when it reaches 3.
How do I do this?

Best Answer

Ok, so this is the answer.
% Index of starting cumsum
indices = cellfun(@(C) find(C>0.5), ddvaluecell, 'uniform', 0);
indexes = cellfun(@(x,ii) x(ii),ddindexcell,indices, 'uniform', 0);
% Change cell into array
indexarray = padcat(indexes{:}); % Pad rows with PADCAT function
indexarr = indexarray(:).'; % Change into column form
indexarr = indexarr(~isnan(indexarr)); % Remove all NaN
sumsum = zeros(0,size(rain,2));
indsum = [];
indend = [];
for bi = indexarr % Iterate over start indices (1x140)
cs = cumsum(rain(bi:end));
csp = find(cs <= 2.5); % Stop when reach 2.5mm
if numel(csp) <= 5 % Cumsum less than 5 days is used
inds3_5 = bi-1 + csp;
sumsum = [sumsum;rain(inds3_5,:)]; % append data
indsum = [indsum; inds3_5]; % append indices
ddearly = [indsum, sumsum]; % Index and value side by side
indend = [indend; inds3_5(end)]; % Last index of cumsum
end
end