I want to divide one vector to two vectors that complement each other .. How can I obtain all possible combinations of these 2 vectors ?

1 visualización (últimos 30 días)
I want to divide this vector [7 3 3 3 3 3 2 1 1 2] into 2 vectors that complement each other, for example: divide it to : A = [4 2 1 2 1 1 1 1 1 0] and B = [3 1 2 1 2 2 1 0 0 2] .. How can I obtain the all combinations of these 2 vectors ?

Respuesta aceptada

James Tursa
James Tursa el 2 de Jun. de 2017
Editada: James Tursa el 2 de Jun. de 2017
You could use the FEX submission ALLCOMB by Jos for this. E.g.,
x = your original vector of non-negative integers
c = cellfun(@(y)0:y,num2cell(x),'uni',false);
A = allcomb(c{:});
B = bsxfun(@minus,x,A);
The rows of A and B contain all of the possibilities. The usual caveat applies here ... if you have too many numbers with values that are too high this will blow up your memory and you will need to solve your problem a different way.
ALLCOMB can be found here:
https://www.mathworks.com/matlabcentral/fileexchange/10064-allcomb-varargin-
  5 comentarios
Mahmoud Ahmed
Mahmoud Ahmed el 3 de Jun. de 2017
Ok .. Done :) I have another problem: There is variable in the workspace that I want to see its values, but matlab said: Cannot display summaries of variables with more than 524288 elements. What can I do ?
Walter Roberson
Walter Roberson el 3 de Jun. de 2017
You could get a job with Mathworks and help them to change that limit of 2^19 elements.
Or you could call max() and min() and whatever on the arrays when you want to know the summary statistics, and you could disp() portions of it. Or you could assign a sub-portion of the large array to a variable and then look at the new variable in the workspace browser.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Variables 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