how save diplayed data?

hi,
i have the following code:
fid=fopen('webscopG.txt');
for j=1:100000
tline = fgetl(fid);
i=i+1;
if ~ischar(tline), break, end
disp(tline);
end
fclose(fid);
this code will display tline as array, and that what I need . But how I can save this array of tline.
thanks

2 件のコメント

Image Analyst
Image Analyst 2012 年 4 月 6 日
Save it how? In a different text file? In a .mat file?
huda nawaf
huda nawaf 2012 年 4 月 12 日
text file

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2012 年 4 月 6 日

0 投票

If you are unable to modify that source, then consider the diary command, or consider executing that source within evalc() and writing out the characters you get back from evalc().
Much better would be to follow IA's suggestion of writing to a file within the loop itself. fopen(), fprintf(), eventually fclose()

6 件のコメント

Walter Roberson
Walter Roberson 2012 年 4 月 12 日
fid=fopen('webscopG.txt');
outfid=fopen('webscopOut.txt','wt');
for j=1:100000
tline = fgetl(fid);
if ~ischar(tline), break, end
i=i+1;
fprintf(outfid, '%s\n', tline);
end
fclose(fid);
fclose(outfid);
huda nawaf
huda nawaf 2012 年 4 月 12 日
I can not because tline save just last line
Image Analyst
Image Analyst 2012 年 4 月 12 日
I don't see why Walter's code wouldn't work. Maybe you should just try this:
copyfile('webscopG.txt', 'webscopG_Copy.txt');
After all, you're simply just transferring lines.
Walter Roberson
Walter Roberson 2012 年 4 月 12 日
Huda, notice that tline is fprintf()'d within the loop, not after the loop.
If you want a variable to contain all of the lines after the loop, store tline into a cell array.
huda nawaf
huda nawaf 2012 年 4 月 13 日
many thanks walter,
Now I want to save tlines from sepecific position,i.e I do not print it from first line. what i have to do?
thanks
Walter Roberson
Walter Roberson 2012 年 4 月 13 日
if (i >= RangeStart) && (i <= RangeEnd); fprintf(....); end

サインインしてコメントする。

その他の回答 (2 件)

Thijs
Thijs 2012 年 4 月 6 日

0 投票

fid=fopen('webscopG.txt');
for j=1:100000
tline{i} = fgetl(fid);
i=i+1;
if ~ischar(tline),
break,
end
disp(tline);
end fclose(fid);
does that work?

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 4 月 6 日
No, you cannot have "fclose" in the same statement as "end".

サインインしてコメントする。

Image Analyst
Image Analyst 2012 年 4 月 6 日

0 投票

Maybe open a second file for writing and write it out with fprintf()?

1 件のコメント

huda nawaf
huda nawaf 2012 年 4 月 12 日
I can not do that, because the tline save just last line

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by