フィルターのクリア

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 Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by