フィルターのクリア

how to generate a vector of binary code

2 ビュー (過去 30 日間)
kurdistan mohsin
kurdistan mohsin 2022 年 7 月 2 日
コメント済み: kurdistan mohsin 2022 年 7 月 2 日
hello , i want to generate a vector of size 10 of binary code(zeros and ones ) ,any one can help?

採用された回答

Raghav
Raghav 2022 年 7 月 2 日
編集済み: Raghav 2022 年 7 月 2 日
Use "arr=true(1,10)" or "arr=false(1,10)" to generate a logical array named "arr" of size 1*10.
But if you want an array of size 1*10, with random 0s and 1s use the "randi()" in MATLAB:
arr=randi(2,1,10)-1
If you want to generate array of different size with similar random constraints, then you can read the below attached documentation :
  1 件のコメント
kurdistan mohsin
kurdistan mohsin 2022 年 7 月 2 日
thank you so much!

サインインしてコメントする。

その他の回答 (1 件)

Voss
Voss 2022 年 7 月 2 日
Here you go:
% a numeric vector of length 10, containing zeros and ones:
[zeros(1,4) ones(1,6)]
ans = 1×10
0 0 0 0 1 1 1 1 1 1
% a logical vector of length 10, containing 'false's and 'true's:
[false(1,3) true(1,5) false(1,2)]
ans = 1×10 logical array
0 0 0 1 1 1 1 1 0 0
% a character vector of length 10, containing '0's and '1's
'1010110001'
ans = '1010110001'
  1 件のコメント
kurdistan mohsin
kurdistan mohsin 2022 年 7 月 2 日
thanks alot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by