How can i generalize what is inside the ndgrid function?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
metehan akinci
am 10 Mär. 2019
Kommentiert: metehan akinci
am 13 Mär. 2019
I have a Values Matrix
Values={[3 4],[2],[3 4 5]} %% which is randomly created.
[Numbers{1:length(Values)}]=ndgrid(Values{1},Values{2},Values{3}); which i want to find.
The problem is that i want to generalize the right sidet so that if Values changes i dont want to re-write my code again.
This is what i tried but couldnt worked it out
for i=1:length(Values)
c(i)={'Values'};
end
Pattern=strjoin(strcat(c,'{%d}'),',');
for a=1:length(Values)
b(a)=a;
end
a=sprintf(Pattern,b) %%%%% which gives me Values{1},Values{2},Values{3}
when i put it in a ndgrid function it doesnt give me the correct answer.
ndgrid(a)
How can i solve this problem? Thanks!
2 Kommentare
Akzeptierte Antwort
Walter Roberson
am 10 Mär. 2019
Bearbeitet: Walter Roberson
am 10 Mär. 2019
nv = length(Values);
Numbers = cell(nv, 1);
[Numbers{:}] = ndgrid(Values{:});
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!