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

New to MATLAB?

How to write new data in new lines in a single file

Asked by Arman Kam

Arman Kam (view profile)

on 26 May 2013

I want to write data into a file and in new lines.

Below is an example of what I want to do. (And I insist on this process to get the results right, because i can not change any part of the code)

   clc;
  clear all;
  for i=1:10
      exampel(i);
  end

and the function "example" is:

function haha(i)
fileDImax=fopen('5.txt');
fprintf(fileDImax,'%6.8f\r\n',i);
fclose(fileDImax);
end

but as it is shown, it doesn't give me what i want. It just overwrite the file with single data and what is left after the analysis in the file is 10!

0 Comments

Arman Kam

Arman Kam (view profile)

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson

Walter Roberson (view profile)

on 26 May 2013
Accepted answer

That should not work at all: when you do not specify an access type, the default is 'r' which should be read-only.

Try

fileDImax=fopen('5.txt', 'a');

0 Comments

Walter Roberson

Walter Roberson (view profile)

Contact us