Single-byte characters?
조회 수: 18 (최근 30일)
이전 댓글 표시
Hi!
If I understand correctly, characters in Matlab are always defined as two-byte variables? Is it possible to define a single-byte character?
I'm trying to communicate with an external device, and I need to send it a character string of N bytes = N characters. At the moment, however, when I define my string in Matlab I always get 2*N bytes.
Is it possible to create strings of characters where each character is stored as one byte?
Thanks!
댓글 수: 0
답변 (4개)
Patrick Kalita
2011년 5월 24일
Does this work for you?
>> s = uint8('hello world')
s =
104 101 108 108 111 32 119 111 114 108 100
>> whos
Name Size Bytes Class Attributes
s 1x11 11 uint8
>>
댓글 수: 1
Jan
2011년 5월 24일
If the function expects a CHAR, you must provide 2-byte characters. 1-byte characters are simply not CHARs and will be refused by the called function.
Please post any details about the program used for "communication with an external device".
댓글 수: 0
Lipa
2011년 5월 24일
댓글 수: 1
Patrick Kalita
2011년 5월 24일
Which function is giving you the error? Is it something provided by MATLAB or a Toolbox?
Laura Proctor
2011년 5월 24일
You can try the function unicode2native which will convert your characters into numeric bytes depending on the encoding scheme that you select:
bytes = unicode2native('hello world','UTF-8')
But I don't know that this will resolve the issue. Can you copy and paste the exact command you are using as well as the error message?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!