×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Adding Data to an existing file with matlab

Adding Data to an existing file with matlab

Adding Data to an existing file with matlab

(OP)
anyone know how to add data to an existing data file.

ie, i have a data file and i want to add a new line of data (matrices) to the file.

i have looked at the save -append option but that overwrites existing variables and can only be used on .mat files (i think), i am using .dat files.

basically everytime i run my script i want it add a new line of data to my results data file.

hope someone else has worked this out!!

any help is greatly appreciated.

RE: Adding Data to an existing file with matlab

Hello:

Try this piece of code

Fid=fopen('path_and_name.ext','a');
fprintf(Fid,'What you want to add');
fclose(Fid);

RE: Adding Data to an existing file with matlab

(OP)
smesajar,

yes thats right...after a bit of research i came up with this:

note the 'a+' - to append to the existing file

fid = fopen('file.txt','a+');
fprintf(fid,'\n');
fprintf(fid,'%9.4f',var1,var2,var3);
fclose(fid);

fprintf is very powerful function - can generated very nicely formatted data files!

for more info on fprintf see:-

http://www.mathworks.com/access/helpdesk/help/techdoc/r...

cheerio

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources