简体   繁体   中英

Octave: Saving Files In a loop

I am currently working on a project that involves long csv files. I have a for loop that separates different values in the time column, then finds the max in each section of time (there are many data points for each point in time). I want to save the data as either a .csv or a .dat, but I can only seem to save either the first or the last value. How can I get octave to save data in a new row on every pass through the loop?

If you are not too keen on writing to file on every loop which is generally slow, you can accumulate data in a variable and write data in one go.

     X = []; 

     for i = 1:100,
          X = [X;i]; //instead of i you can use row vectors 
     end      

     save("myfile.dat",'X');     

And if you are keen on loops then use '-append' option

      X = [];
      for i = 1 : 10,
        save("-append","myfile.dat",'i');
      end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM