MATLAB Answers

huda nawaf
0

how save diplayed data?

Asked by huda nawaf
on 6 Apr 2012

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 Comments

Save it how? In a different text file? In a .mat file?

text file

Tags

Products

No products are associated with this question.

3 Answers

Answer by Walter Roberson
on 6 Apr 2012
 Accepted answer

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 Comments

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.

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

if (i >= RangeStart) && (i <= RangeEnd); fprintf(....); end


Answer by Thijs
on 6 Apr 2012

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 Comment

No, you cannot have "fclose" in the same statement as "end".


Answer by Image Analyst
on 6 Apr 2012

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

  1 Comment

I can not do that, because the tline save just last line


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!