How to define 1-bit variable in data dictionary?

6 ビュー (過去 30 日間)
창희
창희 2025 年 9 月 18 日
コメント済み: Walter Roberson 2025 年 9 月 19 日
FF variable was defined as fixdt(0,1,0) in Data Dictionary.
But it was defined uint8_T after auto-generation.
I want it to be defined as 1-bit variable.
Is there any helpful tip?

採用された回答

John D'Errico
John D'Errico 2025 年 9 月 18 日
編集済み: John D'Errico 2025 年 9 月 18 日
MATLAB does not have a true 1-bit data class.
Even a logical, which is clearly a 1 bit thing, thus either true or false, is stored in a byte.
F = false;
T = true(1,10);
whos F T
Name Size Bytes Class Attributes F 1x1 1 logical T 1x10 10 logical
The best you can do is a uint8. At least, unless you write your own code at a deeper level in C. Or, if you wrote your own class, you could use bit manipulation to store information as vectors of single bits of an integer class. That would make it possible to store integer vectors (of single bits) of length 8 (or multiples thereof) as uint8 integers. But it would force you to do the work to access each bit.
  1 件のコメント
Walter Roberson
Walter Roberson 2025 年 9 月 19 日
T = true(1,10);
B = typecast(T, 'uint8');
whos T B
Name Size Bytes Class Attributes B 1x10 10 uint8 T 1x10 10 logical
The fact that both variables show up as 10 bytes proves that logical values are stored as complete bytes

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by