MATLAB: How to index a cell array

cell arraysindex

Hallo,
I have a structure (K) with many fields, containg a field (elevation) which is (161*1 cell) array, each cell is a matrix (n*1) double.
I wanted to find all the elements in each matrix that is more than 0 then calculate the area of these values (above 0)
firstly I made a new cell array of the indexs that I needed
idx = arrayfun(@(K) K.elevation >=0, K, 'UniformOutput', false)';
now I want to use the function trapz to find the area
I tried many things, but I'm getting always errors like 'Unable to use a value of type cell as an index or 'Expected one output from a curly brace or dot indexing expression, but there were 161 results'
Can someone help me with this issue?
many thanks!

Best Answer

Try :
area_r = arrayfun(@(a) cellfun(@(c) trapz(c(c>=0)),a.elevation,'UniformOutput',false), K, 'UniformOutput',false);
I hope it helps !