>> cell2mat(arrayfun(@(x,y) repmat(x,y,1),IDX1,segMem1,'uniform',0).')
ans =
1
1
1
2
2
1
1
3
4
4
>>
Since Matlab doesn't know about jagged arrays other than by cell array, you'll have to build the pieces and rearrange them into a cell array.
Oh, a spurious thought though I've never tried it; I suppose one could wrap a cellfun call around arrayfun, maybe to process the two cells as you've smushed them together above; otherwise a loop or the cell array.
ADDENDUM
OK, the looping construction works well enough...
>> for i=1:length(IDX)
idx=IDX{i};
seg=s{i};
cell2mat(arrayfun(@(x,y) repmat(x,1,y),idx,seg,'uniform',0))
end
ans =
1 1 1 2 2 1 1 3 4 4
ans =
3 3 1 2 2 1 1
>>
Left as row vectors for more compact display...
Best Answer