Help me to store the values into a text file.
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Walter Roberson
2021 年 6 月 11 日
S = '29 C3 50 5F 57 14 20 F6 40 22 99 B3 1A 02 D7 3A'
Schar = char(sscanf(S, '%x', [1 inf]))
[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
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!