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

2 ビュー (過去 30 日間)
jaah navi
jaah navi 2021 年 6 月 23 日
コメント済み: Walter Roberson 2021 年 6 月 24 日
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 Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by