Azzera filtri
Azzera filtri

copy a line from a txt to other txt

2 visualizzazioni (ultimi 30 giorni)
jose bernardo
jose bernardo il 8 Nov 2013
Risposto: Simon il 8 Nov 2013
Hello:
I have this code witch copy all lines of a file(fid01)to other file(fid02)
tline = fgetl(fid01);
while ischar(tline)
disp(tline)
fprintf(fid02,'%s\r\n',tline);
tline = fgetl(fid01);
end
fclose(fid01);
fclose(fid02);
How I can change this code to copy only the third line of fid01 to fid02???
Thanks

Risposta accettata

Simon
Simon il 8 Nov 2013
Hi!
count = 1;
tline = fgetl(fid01);
while ischar(tline)
count = count + 1;
disp(tline)
if count == 3
fprintf(fid02,'%s\r\n',tline);
end
tline = fgetl(fid01);
end
fclose(fid01);
fclose(fid02);
You can do as well
for n = 1:3
tline = fgetl(fid01);
end
fprintf(fid02,'%s\r\n',tline);
fclose(fid01);
fclose(fid02);

Più risposte (0)

Categorie

Scopri di più su Large Files and Big Data in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by