필터 지우기
필터 지우기

Help me to store the values into a text file.

조회 수: 1 (최근 30일)
Aiswarya Babu
Aiswarya Babu 2021년 6월 11일
댓글: Walter Roberson 2021년 6월 11일
These are the values i need to store as a text file .
29 C3 50 5F 57 14 20 F6 40 22 99 B3 1A 02 D7 3A
Kindly help me.

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 11일
S = '29 C3 50 5F 57 14 20 F6 40 22 99 B3 1A 02 D7 3A'
S = '29 C3 50 5F 57 14 20 F6 40 22 99 B3 1A 02 D7 3A'
Schar = char(sscanf(S, '%x', [1 inf]))
Schar = ')ÃP_W ö@"³×:'
[fid, msg] = fopen('a text file.txt', 'wt');
if fid < 0
error('failed to open file for writing because: "%s"', msg);
end
fprintf(fid, '%s\n', Schar);
fclose(fid);
You should not be astonished if you can only read back 12 out of the 16 bytes of the result. You are using MS Windows, and in MS Windows, when you store as a TEXT file, the 0x1A (decimal 26) is the End Of File character. If you happened to have bytes that were 0A then you should expect that when you write as a TEXT file that those bytes would be converted to CR/LF pairs (0C 0A)
Which is to say that storing in TEXT files is a mistake when what you have to store is BINARY data.
  댓글 수: 3
Walter Roberson
Walter Roberson 2021년 6월 11일
S = '29 C3 50 5F 57 14 20 F6 40 22 99 B3 1A 02 D7 3A'
Sbyte = uint8(sscanf(S, '%x', [1 inf]));
[fid, msg] = fopen('a sound file.wav', 'w');
if fid < 0
error('failed to open file for writing because: "%s"', msg);
end
fwrite(fid, Sbyte, 'uint8');
fclose(fid);
This assumes that the stream of bytes holds the entire wav file, and not just the sound data information. For example if the original file contained track information, then that would have had to have been transmitted as well in order for the above method to work.
If what was transmitted was just the sound data, then you need to tell us how the sound was encoded into binary. Most wav files (but not all) use 16 bit unsigned integers internally, but most people who read wav files in MATLAB receive double precision values instead, with a special 'native' option being required to receive the unsigned integers.
Walter Roberson
Walter Roberson 2021년 6월 11일
(My tracking number: T0098915)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by