HELP! All combinations of array of vectors
2 次查看(过去 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!