Unicode.txt to binary matrix & vice versa

조회 수: 7 (최근 30일)
Juha-Matti Huusko
Juha-Matti Huusko 2011년 3월 24일
I have a text file greek.txt. It is in unicode and it has the content:
??????
How can I get the unicode values of these letters to a Matlab matrix?
Using http://software.ellerton.net/txt2bin/ I see that the matrix would be
A =
1111000110
1111000001
1110110101
1111000011
1111101110110
1110111101
if I succeeded in this I could very easily do some text editing for my task.
Vice versa, if I have a matrix
I have a text file greek.txt. It is in unicode and it has the content:
??????
How can I get the unicode values of these letters to a Matlab matrix?
Using http://software.ellerton.net/txt2bin/ I see that the matrix would be
A =
1111000110
1111000001
1110110101
1111000011
1111101110110
1110111101
how can I produce a text file greek.txt from it such that it says
??????
I have spent too many hours on the internet trying to solve this. Thanks for help.
  댓글 수: 1
Juha-Matti Huusko
Juha-Matti Huusko 2011년 3월 24일
and I see that the greek letters have become to ??????
they are
phi rho epsilon sigma iota nu
and they form a word

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2011년 3월 24일
I'm not sure if this does what you need, but it is worth to try:
FID = fopen(FileName, 'rt', '', 'UTF-8');
Data = fread(FID, 6, 'char');
dec2bin(Data)
fclose(FID);
Read the help text of FOPEN for other encoding schemes.
If your file is UTF16 encoded, this could work also:
FID = fopen(FileName, 'r');
Data = fread(FID, 6, 'uint16');
dec2bin(Data)
fclose(FID);
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 3월 24일
You might need to use '*char' insted of 'char' in the first possibility.
Jan
Jan 2011년 3월 25일
@Walter: '*char' replies a CHAR array, 'char' replies a DOUBLE array. Both are valid inputs for DEC2BIN.
@Jussi: Please use '*char' if this works better. Perhaps NATIVE2UNICODE and UNICODE2NATIVE are useful also.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by