Search code examples
arraysmatlabcell

how to convert two-columned cell array into matrix with points (each pair of elements from each row of cell array) MATLAB


I have an cell Array (input) like this:

A(1,1) = {[1 2]};   A(1,2) = {[4 5 6]};

now for each row of A (in this case only 1) I would like to obtian the vector of points like this:

A_row1 =[ 1 4; 1 5; 1 6; 2 4; 2 5; 2 6]

I wonder if there is any method to cope with this without a loop?


Solution

  • How about:

    [x, y] = ndgrid(A{1}, A{2})
    B = [x(:) y(:)]