Azzera filtri
Azzera filtri

Dynamically generating a set of combinations for elements of a vector

1 visualizzazione (ultimi 30 giorni)
Hi there,
I have to dynamically define a vector m = (m_x, m_y, m_z) where each of the 3 elements in m can take values between -Nm and Nm creating a set of (2Nm +1)^2 combinations. Can anyone help me define all combinations of the possible values of m for a given value of Nm?
Thank you!!

Risposte (1)

Walter Roberson
Walter Roberson il 18 Ott 2016
The functions I show there are for 6 sets, but otherwise the code is generalized -- notice there that the first thing I do is toss the values to select from into a cell array, so you can follow on from after that step if your values are already in a cell array.
  1 Commento
Mark Thompson
Mark Thompson il 19 Ott 2016
Hi Walter,
I have managed to look at your method, and whilst technically it appears to be providing a "mesh" of combinations it doesn't present all of the combinations back in groups of 3 values (i.e. mx, my and mz).
I did learn that I have access to the combvec() function with my current MATLAB license so I have managed to implement this solution using the following:
Nm = 6;
mx = (-1*Nm):1:Nm;
my = (-1*Nm):1:Nm;
mz = (-1*Nm):1:Nm;
m = combvec(mx,my,mz)';
The resulting array (2197x3) m after executing this code contains 2197 rows of unique combinations of mx, my and mz, which is what I was originally after.
Thank you again for providing your method for consideration though.

Accedi per commentare.

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by