HELP! All combinations of array of vectors

2 visualizaciones (últimos 30 días)
Emiliano Cimoli
Emiliano Cimoli el 18 de Abr. de 2015
Comentada: Emiliano Cimoli el 19 de Mayo de 2015
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

Respuesta aceptada

pfb
pfb el 18 de Abr. de 2015
Editada: pfb el 18 de Abr. de 2015
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 comentario
Emiliano Cimoli
Emiliano Cimoli el 19 de Mayo de 2015
Thanks man i am going to try it out and let you know!, sorry for the really late reply!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by