could anyone help me to solve the issue in the following command

1 visualización (últimos 30 días)
when i run the command
B = arrayfun(@(N) randi(2,N), repelem((1:3).',5), 'uniform', 0)
i am getting B = 15×1 cell array
{[ 1]}
{[ 1]}
{[ 1]}
{[ 2]}
{[ 2]}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{3×3 double}
{3×3 double}
{3×3 double}
{3×3 double}
{3×3 double} and the data inside are
3
2
2
2
2
[1,1;1,1]
[1,1;2,1]
[1,3;3,1]
[3,1;1,3]
[1,1;1,1]
[1,1,3;1,2,2;1,2,1]
[3,2,2;3,1,3;1,2,3]
[1,2,2;1,3,1;1,2,3]
[3,1,1;3,3,1;3,2,3]
[3,2,1;3,1,1;3,2,1]
but I actually need B =
15×1 cell array
{1×1double}
{1×1 double}
{1×1 double}
{1×1 double}
{1×1 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×3 double}
{1×3 double}
{1×3 double}
{1×3 double}
{1×3 double} containing the following values
3
2
2
2
2
[1,1]
[1,1]
[1,3]
[3,1]
[1,1]
[1,1,3]
[3,2,2]
[1,2,2]
[3,1,1]
[3,2,1]
could anyone please help me to get it.

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Jun. de 2021
B = arrayfun(@(N) randi(2,1,N), repelem((1:3).',5), 'uniform', 0)
  2 comentarios
jaah navi
jaah navi el 24 de Jun. de 2021
If i run the above the command it generates 15x1 cell array. thanks for it.
But i need to have for row having 1x1 double the value should be of 1 and not more than 1 and for 1x2 the value should be of [1,2 ], [1,1], [2,1] and not more than 2, [2,2]...
for 1x3 double the value should be [1,2,3], [3,2,1], [1, 2,2] and not more than 3 and should ignore [1,3,3] as it leaves 2.
Could you please help me to write how should I need to cell array in the above mentioned manner.
Walter Roberson
Walter Roberson el 24 de Jun. de 2021
You have a fixed outcome, and you have no explainable reason for that particular outcome. You should just write static assignment statements.
Remember the fundamental rule of practical programming: get it working first, and worry about making it shorter or faster later. You have been held up for days trying to write these things in a compact way, when you could have just written something that got the required outcome and moved on to the next step.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays 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