como crear una matriz que contenga la variación con repetición de n elementos
3 次查看(过去 30 天)
显示 更早的评论
ej
Para los numeros 0 y 1 la matriz que busco sería
M=[00;01;10:11]
Para los numeros 0, 1, 2 la matriz que busco sería
V=[0,1,2]
M=[000;001;010;011;100;101;110;111;111;121;122;211;212;221;222;002;020;022;200;202;220;222;012;021;102;120;210;201]
lo ideal seria poder meter un vector con los numeros de los que quiero conseguir la variación con repetición
gracias
0 个评论
回答(1 个)
Bhanu Prakash
2023-10-12
Hi Guillermo,
I understand that you want to create an array that represents all possible combinations of digits for a given set of numbers.
Consider the code below:
V = [0, 1, 2]; % Replace with your desired set of numbers
numDigits = numel(V); % Replace with the desired number of digits
% Generate all possible combinations of digits
combinations = dec2bin(0:(2^numDigits-1), numDigits) - '0';
% Convert combinations to a matrix
M = combinations * diag(numbers);
The above code takes the set of numbers from the matrix ‘V’ and uses the function ‘dec2bin’ to find all the combinations of the given set of numbers.
The desired matrix ‘M’ can be obtained by multiplying the combinations with the ‘numbers’ array. This operation assigns the corresponding values from the numbers array to each digit in the combinations, resulting in the desired matrix.
For more information on the above-mentioned functions, refer to the following documentation:
For ‘numel’ function:
For ‘diag’ function:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!