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: Ganesh Kini
Subject: Re: Values ​​not getting printed in csv file
Date: Mon, 8 Jun 2020 00:17:21 +0200

Thank so much, I got the results
I need one help, thats when i have
[fid1, msg1]   = fopen('file1.csv', 'wt' );
fprintf (fid1, 'Temperature \t');
fprintf('\n');
fprintf (fid1, 'Value_n \t');
fprintf('\n');
fprintf (fid1, 'Value_p\t');

for
    for
        for
            ...
            fprintf (fid, '% 3.0f \ n' , temp)
             fprintf (fid1, '% 1.1f\t' , vnw);
            fprintf (fid1, '% 1.1f\t' , vpw);

        end
    end
end

I get the output
 
Temperature VNW VPW-40 1.8 -1.5 0 1.2 -1.8 25 1.2 -1.8 60 1.2 -1.5 -40 1.2 -1.8 0 1.8 -1.2 25 0.9 -1.8 60 0.9 -1.8 -40 0.9 -1.8 0 0.9 -1.8 25 0.9 -1.8 60 0.9-1.5

in a single line, but I should get the values in 3 different lines
Temperature 40,0,25  and so on ----------
Value_n 1.8, 1.2,1.2  and so on ----------
Value_p -1.5,-1.8, -1.8  and so on ----------

How do I assign each Temperature values to only temperature, Value_n to VNW and Value_p to VPW ? please help

On Sun, Jun 7, 2020 at 7:56 PM N <nicklas.karlsson17@gmail.com> wrote:
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]