Unspecified number of dimension for ndgrid

1 回表示 (過去 30 日間)
Fernando
Fernando 2023 年 7 月 5 日
コメント済み: Fernando 2023 年 7 月 5 日
Hello,
I want to produce a space with N number of dimensions using ndgrid where N will depend on another part of the program. The thing is, depending on an earlier section of the progrm N can be any integer starting from 1 but N is known at this point; it's just not constant. Therefore I can't just set the specified domain into ndgrid, say [X,Y,Z]= ndgrid(x,y,z) where x,y,z = 0:0.1:10.
The next part of code is how it is supposed to look if N was constant:
x1=0:0.1:10; x2=0:0.1:10;
domain = {x1,x2};
[X1,X2] = ndgrid(domain{1,1},domain{1,2});
I was thinking of somehow implementing a for loop which would increase ndgrid(domain{1,1},domain{1,2},...,domain{1,n}) until n=N. But I'm quite stuck.
The other thing is that X1,X2,... would have to increase to N to keep the number of dimensions constant.
Thank you!

採用された回答

Torsten
Torsten 2023 年 7 月 5 日
  1 件のコメント
Fernando
Fernando 2023 年 7 月 5 日
Perfect thanks!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by