Concatenate certain elements from a cell array into a numeric array - MATLAB -
i have nested cell array a
, illustration a
1 x 6
cell.
each cell of a
contains array of cells (for ex. a{1} = 1 x n
cell).
each cell of a{1}{1}
contains other cell arrays a{1}{1} = 1 x n
cell
i list content of cell in unique array.
a = cell(1,2); a{1} = cell(1,2); a{2} = cell(1,1); a{1}{1} = [{1} {2}]; a{1}{2} = [{3} {4}]; a{2}{1} = [{5} {6}]; vec = []; = 1 : size(a,2) j = 1 : size(a{1,i},2) vec = [vec; cell2mat(a{1,i}{1,j}(:,2))]; end end vec = [2;4;6]
is there way avoid loop?
thanks
see works -
a_horzcat = horzcat(a{:}) out = cell2mat(vertcat(a_horzcat{:})) vec = out(:,2)
another approach (a one-liner! , better) -
vec = arrayfun(@(x) x{1}{2}, [a{:}]).'
matlab cell-array
No comments:
Post a Comment