Text reader to numbers
古いコメントを表示
I have to make a program that goes through a text file and extracts numerical values, I am having a hard time extracting those numbers, here is what I have so far. The text file also has a lot if letters associated with it to

6 件のコメント
Shawntae Harris
2020 年 7 月 22 日
編集済み: per isakson
2020 年 7 月 22 日
Shawntae Harris
2020 年 7 月 22 日
Walter Roberson
2020 年 7 月 22 日
MATLAB does not permit us to copy and paste pictures of code or text and have them processed as text.
Walter Roberson
2020 年 7 月 22 日
So the lines for '2 FAIL OPEN_CIRCUIT' should be located? And is it the 22.8125 that you need, or the 100 0.00 on the next line that you need?
Shawntae Harris
2020 年 7 月 22 日
Shawntae Harris
2020 年 7 月 22 日
採用された回答
その他の回答 (1 件)
Mohammad Sami
2020 年 7 月 22 日
編集済み: Mohammad Sami
2020 年 7 月 22 日
Assuming the pattern shown in your picture. Ignore line 1, line 2& line 3 form a repeating pattern.
I would suggest read the entire file first. Then we split it by line. Then put the line following line 2 pattern together and same for line3.
file = 'filename.txt';
fid = fopen(file,'r');
rawtxt = fread(fid,'*char')';
rawtxt = splitlines(rawtxt);
line2s = rawtxt(2:2:end);
line3s = rawtxt(3:2:end);
line2txt = strjoin(line2s,newline);
line3txt = strjoin(line3s,newline);
out2 = textscan(line2txt,'%f FAIL OPEN_CIRCUIT Int %f degC');
out3 = textscan(line3txt,'%f %f W/m^2');
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
