# MATLAB: Create symbolic expressions when using ndgrid

generate expressionsndgrid

I try to use function Ndgrid to get the grid coordinators.
Such as
[X1,X2,X3,...,Xn] = ndgrid(x1gv,x2gv,x3gv,...,xngv)
Suppose that the grid vectors are as each columns in a matrix M of size m-by-n.
Can someone help me to get the expression in the brackets, i.e. x1gv,x2gv,x3gv,…,xngv, please?
Thank you.

• [m, n] = size(M);temp = mat2cell(M, m, ones(1, n) );[X{1:n}] = ndgrid(temp{:});temp2 = cellfun(@(v) v(:), X, 'uniform', 0);result = horzcat(temp2{:});