copy a line from a txt to other txt

2 次查看(过去 30 天)
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

采纳的回答

Simon
Simon 2013-11-8
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by