Filter löschen
Filter löschen

All combinations not being generated

1 Ansicht (letzte 30 Tage)
klb
klb am 29 Nov. 2020
Kommentiert: klb am 29 Nov. 2020
Hello everyone,
Running a code to get all combinations of vector. Each combination is unique on its own. Meaning, [.4, .1, .1] is different from [.1, .1, .4] and so on.
Ok, here is the code
A = [0.4, 0.25, 0.1] %vector
[A1,A2,A3] = ndgrid(A);
my_matrix= [A3(:),A2(:),A3(:)]
It does not give all combinations. In fact, the example stated above is missing.
If you run it and have a look at the last column, you'll see it is copy of the first column.
What am I doing wrong?
Thanks in advance!

Akzeptierte Antwort

klb
klb am 29 Nov. 2020
update: In line 3 of the code A3(:) is repeated twice, resulting in the 'error'
Follwing is what it should read :
my_matrix= [A1(:),A2(:),A3(:)]

Weitere Antworten (1)

David Hill
David Hill am 29 Nov. 2020
  3 Kommentare
Rik
Rik am 29 Nov. 2020
I would suggest reverting your edit, posting your edit as an answer and accept it.
klb
klb am 29 Nov. 2020
done.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB 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!

Translated by