[help] copy a line from a file
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone. I have 360 files(.o) (from test(0).o-test(360).o), as figure. I want to copy a line (red framed) and put it in the new .txt file (ordinarily from 0 to 360 means in 361 lines) I can do it when copy line "3.5700E-01...." or other lines that contain only number, when I try to copy line of "total" it is not working.
Where the code is not working when copy a "total" line (red framed).
Thank you
clc;
clear;
file_gen=fopen('result1.txt','wt' );
for i=0:1:360 % ÃÑ ÆÄÀϰ¹¼ö ¸¸Å
count=i;
file_open=fopen(['test(' num2str(count) ').o'],'r' );
while 1 % tally 8 ã±â
tline=fgets(file_open);
find_tally=findstr(tline,'cell 100');
if find_tally==2
break;
end
end
while 1
tline=fgets(file_open);
find_end=findstr(tline,'3.5700E-01'); % Àüü n ¼ö ÀÔ·Â
if find_end==5 % °ø¹é¼ö ÀÔ·Â (È®ÀÎÇÊ¿ä)
break;
end
end
tline_arr=tline(1:35);
conv_tline=str2num(tline_arr);
fprintf(file_gen,'%s %d %d %d \r\n', num2str(count), conv_tline(1), conv_tline(2), conv_tline(3));
fclose(file_open);
end

0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!