I got unread file using Fprintf, and that is the first time I got that error
3 ビュー (過去 30 日間)
古いコメントを表示
After six days of running, I found the file with the attached case
I know it is a matter of encoding issue, but is there a way that I can read the contents of the file
I really appreciate the help
3 件のコメント
dpb
2021 年 2 月 4 日
編集済み: dpb
2021 年 2 月 4 日
Looks like mixed formatted and unformatted output...first part of file contains
000 0000 0d 0a 36 78 37 78 34 32 20 04 20 08 20 0d 0a 20 ..6x7x42 ♦ ◘ ..
000 0010 0e 20 19 20 0f 20 10 20 11 20 12 20 16 20 1d 20 ♫ ↓ ☼ ► ◄ ↕ ▬ ↔
000 0020 20 20 14 20 17 20 1a 20 26 20 25 20 28 20 0c 20 ¶ ↨ → & % ( .
000 0030 15 20 1b 20 1c 20 1e 20 22 20 01 20 02 20 07 20 § . ∟ ▲ " ☺ ☻ •
000 0040 03 20 09 20 13 20 05 20 0b 20 06 20 0d 20 23 20 ♥ . ‼ ♣ . ♠ . #
000 0050 24 20 21 20 1f 20 18 20 2a 20 27 20 29 0d 0a 36 $ ! ▼ ↑ * ' )..6
000 0060 78 37 78 34 32 20 01 20 03 20 08 20 0c 20 04 20 x7x42 ☺ ♥ ◘ . ♦
000 0070 0f 20 0e 20 19 20 1c 20 1e 20 2a 20 22 20 02 20 ☼ ♫ ↓ ∟ ▲ * " ☻
000 0080 05 20 0d 20 10 20 11 20 14 20 0d 0a 20 06 20 0b ♣ . ► ◄ ¶ .. ♠ .
Spelunking shows...
fid=fopen('LQM_Results.txt','r');
LQM=fread(fid,'*char');
fid=fclose(fid);
ix=find(LQM=='6');
diff(ix(1:10))
ans =
93
93
93
93
93
93
93
93
93
>>
that there are fixed-length records in the file that can be read if knew what the data were. Seeing how written is the key...
回答 (1 件)
Animesh Gupta
2022 年 2 月 2 日
Hello ElWakil,
It is my understanding that you are unable to load non-ascii contents of the provided file.
You may refer the following script which demonstrates how to read the non ascii contents, using textscan function in the form of fixed size string vectors. You may also apply strip method to remove whitespaces.
filename = "test.txt";
fid = fopen(filename, 'w');
nbytes = fprintf(fid, '%s\n', "000 0050 24 20 21 20 1f 20 18 20 2a 20 27 20 29 0d 0a 36 $ ! ▼ ↑ * ' )..6");
fclose(fid);
fid=fopen(filename,'r');
LQM=textscan(fid,'%s');
LQM_char = char(LQM{1});
t = strings(1,length(LQM_char));
for i=1:length(LQM_char)
t(1,i) = strip(LQM_char(i,:));
end
disp(t)
I hope it helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!