HELP! All combinations of array of vectors
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello to everyone, thanks for your attention.
I quite new in Matlab programming, i am trying to figure out something without success, hope you can help!
So i have a an array of Ni elements and each element is a 5 values vector. it looks like this:
- N1) 0.588 8.102 0.001 0.010 0.002
- N2) 0.588 8.102 0.001 0.003 0.002
- N3) 0.588 8.102 0.006 0.001 0.005...Ni
My code process this N elements array. Among other outputs it gives an error estimation of using these values.
What i would like to do is to is the code to process all possible combinations of elements values till the error is minimized.
So for example, using N1, N2
N2, N3
.
.
N1, N2, N3
N2, N3, N4
.
And so on, so all possible combinations among the Ni elements varying also the number elements in the combination.
I am sorry i have not been that clear, i did my best, let me know if further information is needed. Hope you can help, i really need some! I would extremely appreciate.
Best regards Emiliano
댓글 수: 0
채택된 답변
pfb
2015년 4월 18일
편집: pfb
2015년 4월 18일
If I get your problem right, you could use "combnk"
If V is a vector with the indices of your N's, e.g.
V = 1:10
then
combnk(V,3)
gives a matrix whose rows are the combinations of 3 indices taken out of V. So, your code might be something like this
L = 10; % number of N
V = 1:L;
for n = 1:L
C = combnk(V,n); % this is a matrix
% loop over its rows
for r = 1:size(C,1)
c = C(r,:); % this is one particular combination of n elements
% <<< here you do whatever calculation you need to do based on c
end
end
By the way, since each N has 5 entries, it could be worth forming a Lx5 matrix Nm out of it. This way
Nm(c,:)
should contain only the values you need for your calculation with the particular combination in c.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!