필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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.

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 23일
B = arrayfun(@(N) randi(2,1,N), repelem((1:3).',5), 'uniform', 0)
  댓글 수: 2
jaah navi
jaah navi 2021년 6월 24일
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 2021년 6월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by