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!

 채택된 답변

klb
klb 2020년 11월 29일

0 개 추천

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(:)]

추가 답변 (1개)

David Hill
David Hill 2020년 11월 29일

0 개 추천

perms(A);

댓글 수: 3

klb
klb 2020년 11월 29일
Hello David,
perms() skips certian combinations such as [.4, .1, .1] because for perms(), order matters
Also I caught my mistake : in line 3 I am repeating A3(:), twice i.e. it should have been :
my_matrix= [A1(:),A2(:),A3(:)]
I realized that right after posting. But questions cant be deleted. Time to take a break from coding. Thank you for the answer though!
Rik
Rik 2020년 11월 29일
I would suggest reverting your edit, posting your edit as an answer and accept it.
klb
klb 2020년 11월 29일
done.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

klb
2020년 11월 29일

댓글:

klb
2020년 11월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by