MATLAB/OCTAVE Extracting elements from different sized vectors in a cell array

后端 未结 5 726
旧巷少年郎
旧巷少年郎 2021-01-13 21:40

I have a simple question but I can\'t figure it out or find it anywhere. I have a cell array where c{1} is a vector and c{2} is a vector but of different lengths, up to c{i

5条回答
  •  [愿得一人]
    2021-01-13 22:28

    The following one-liner even works for completely inconsistent inputs:

    result = [cell2mat(cellfun(@(x) x(:), A, 'uni', 0)')]'
    

    Example:

    for:

    A{1} = [1, 2, 3, 4, 5];
    A{2} = [6; 7; 8; 9];
    A{3} = [10, 12; 11, 13];
    

    it returns:

    result =
    
         1     2     3     4     5     6     7     8     9    10    11    12    13
    

提交回复
热议问题