필터 지우기
필터 지우기

create symbolic expressions when using ndgrid

조회 수: 1 (최근 30일)
Qun Wu
Qun Wu 2017년 2월 8일
댓글: Qun Wu 2017년 3월 17일
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.

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 16일
[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{:});
  댓글 수: 1
Qun Wu
Qun Wu 2017년 3월 17일
Thank you so much, I thought the question has gone with wind.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Karan Gill
Karan Gill 2017년 2월 13일
If I understand correctly, you are trying to do something like this?
>> A = sym('A%d',[1 4]);
B = sym('B%d',[1 4]);
>> [D1,D2] = ndgrid(A,B)
D1 =
[ A1, A1, A1, A1]
[ A2, A2, A2, A2]
[ A3, A3, A3, A3]
[ A4, A4, A4, A4]
D2 =
[ B1, B2, B3, B4]
[ B1, B2, B3, B4]
[ B1, B2, B3, B4]
[ B1, B2, B3, B4]
  댓글 수: 1
Qun Wu
Qun Wu 2017년 3월 16일
Not really, thanks anyway. I learned a trick from the answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by