Creating a logical array
311 ビュー (過去 30 日間)
古いコメントを表示
hi guys,
How can i create a logical array [1 0 1 0 1 1 ....] 1-by-15 it will go into gamultiobj with bitstring so the the arranging is not important.
0 件のコメント
採用された回答
Azzi Abdelmalek
2012 年 8 月 4 日
x=boolean([0 1 0 1 0 1 0 1])
1 件のコメント
Image Analyst
2023 年 1 月 16 日
Note: the boolean function is only in the Stateflow toolbox which is kind of rare. See the warning in the help:
その他の回答 (2 件)
Image Analyst
2012 年 8 月 4 日
編集済み: Image Analyst
2023 年 1 月 16 日
To get a random placement of trues and falses, use randi
logicalArray = logical(randi(2, [1 15]) - 1)
Otherwise you can put in exactly what you want:
logicalArray = logical([1, 0, 1, 0, 1, 1])
0 件のコメント
Captain Karnage
2023 年 1 月 16 日
What's the ultimate goal? If you need to initialize a logical array, you can use true or false:
either
logicalArray = false(1,15);
-OR-
logicalArray = true(1,15);
will initialize a 1x15 logical array that you can then set the individual values for, then if you set any element, like
logicalArray(5) = 1;
It will be of type logical rather than double.
If you already know your entire array, you can also do it manually with true and false:
logicalArray = [ true false true false true true true false true false true true true false true ];
will output
1 x 15 logical array
[ 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!