Unspecified number of dimension for ndgrid

1 view (last 30 days)
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!

Accepted Answer

Torsten
Torsten on 5 Jul 2023

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!