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

采纳的回答

pfb
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.
  1 个评论
Emiliano Cimoli
Emiliano Cimoli 2015-5-19
Thanks man i am going to try it out and let you know!, sorry for the really late reply!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by