(continued)On the combination of N-dim vector.
Ältere Kommentare anzeigen
Yesterday I asked how to write code to visit every combination of N-dim vector(with entry 0,1 or 2), and it is very helpful by just trying below:
[C{1:N}]=ndgrid(0:2);
M=reshape(vertcat(C{:}),[],N);
Then for i=1:3^N, trying M(i,:) is the answer. However, if I want to add constraint on those 3^N vectors, how to adjust the code?
For example I want all combinations that less than or equal to another vector V(every entry is less than or equal to V's entry). For another one, I want to try those combinations in a order, by least sum of all entries to most.
Thank you for your help!
6 Kommentare
C Zeng
am 24 Mai 2012
Daniel Shub
am 24 Mai 2012
Can you give an example of your constraints for a small N (say 3).
C Zeng
am 25 Mai 2012
Daniel Shub
am 25 Mai 2012
I don't understand your constraints. Edit your question to include the rule and an example of what rows you want.
C Zeng
am 25 Mai 2012
C Zeng
am 5 Jun. 2012
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!