help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Values ​​not getting printed in csv file


From: N
Subject: Re: Values ​​not getting printed in csv file
Date: Sun, 7 Jun 2020 19:56:35 +0200

On Sun, 7 Jun 2020 19:34:34 +0200
Ganesh Kini <ganeshrkini19@gmail.com> wrote:

> Hi
> I have a small issue in printing the values in .csv file
> Code.
> for
> for
> for
> - some lines of code
> fprintf ( "Temperature =% 3.0f \ n" , temp);
> [fid1, msg1] = fopen ( 'file1.csv' , 'w' );
> fprintf (fid1, 'temperature' );
> fprintf (fid, '% 3.0f' , temp);
> fprintf (fid, '\ n' );
> fclose (fid);
> end
> end
> end
> Output on the command line.
> Temperature = -40
> Temperature = 0
> Temperature = 25
> Temperature = 60
> Temperature = -40
> Temperature = 0
> Temperature = 25
> Temperature = 60
> Temperature = -40
> Temperature = 0
> Temperature = 25
> Temperature = 60
> But in the CSV file i have only the last line of the output is printed.
> Temperature = 60
> I need to print all the values, what can be done?


Then you open file in write mode 'w' old data will ber overwritten and you have 
a for loop open/close it several time. Below should work better, first open 
once then save all values and last close once.

  fprintf ( "Temperature =% 3.0f \ n" , temp);
  [fid1, msg1] = fopen ( 'file1.csv' , 'w' );
  for
    fprintf (fid1, 'temperature' );
    fprintf (fid, '% 3.0f' , temp);
    fprintf (fid, '\ n' );
  end
  fclose (fid);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]