help-octave
[Top][All Lists]
Advanced

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

Re: saving files


From: Keith Goodman
Subject: Re: saving files
Date: Wed, 19 Apr 2006 10:40:04 -0700

On 4/19/06, Berta Biescas <address@hidden> wrote:
> Hello,
> I need some help. I have just started using Octave and I'm fighting with
> a problem. I need to save a matrix in a file. I do:
> save -text file variable
> But the file has some comment lines that I don't like. I try to see the
> save_header_format_string but it is an empty array =[] (0x0).
> What can I do?
> Thank you!

Octave offers many ways to save data. If you are saving data that you
would like to reload into octave then use the save command. If you
want to save the data without any formatting, or with your own special
formatting, use fopen, fprintf, and fclose. Or use dlmwrite.m from
Octave-Forge:

>> x = rand(3);
>> dlmwrite('xfile',x,',')
>> system('cat xfile');
0.444926381111145,0.5528771877288818,0.3542591333389282
0.3172010779380798,0.8010092377662659,0.9965974092483521
0.8315058946609497,0.06625500321388245,0.6231693625450134
>>


>> help dlmwrite
dlmwrite is the user-defined function from the file
/usr/share/octave/site/m/octave-forge/io/dlmwrite.m

  -- Function File:  dlmwrite(FILE, A)
  -- Function File:  dmlwrite(FILE, A, DELIM, R, C)
  -- Function File:  dmlwrite(FILE, A, `"attrib1"', VALUE1, `"attrib2"',
          VALUE2, ...)
  -- Function File:  dmlwrite(FILE, A, `"-append"', ...)
     Write the matrix A to the text FILE using delimiters.

    DELIM
          the delimiter to use to separate values on a row

    R
          the number of delimiter-only lines to add to the start of the
          file

    C
          the number of delimiters to prepend to each line of data.

    '-APPEND'
          append to the end of the FILE.

    'APPEND', STATE
          Either `'on'' or `'off''.  See `'-append'' above.

    'DELIMITER', D
          See `"delim"' above.

    'NEWLINE', OS
          The character(s) to use to separate each row.  Three special
          cases exist for this option.  `'unix'' is changed into "\n",
          `'pc'' is changed into "\r\n", and `'mac'' is changed into
          "\r".  Other values for this option are kept as is.

    'ROFFSET', R
          See R above.

    'COFFSET', C
          See C above.

    'PRECISION', P
          The precision to use when writing the file.  It can either be
          a format string (as used by fprintf) or a number of
          significant digits.

          A = reshape(1:16,4,4);
          dlmwrite(`"file.csv"', A)

     Note the extra escaping of the backslashes necessary in using the
     latex delimiter of "\\" with a unix style newline.

          dlmwrite(`"file.tex"', A, `"delimiter"', `"&"', `"newline"',
`"\\\\\n"')

     TODO: proper handling of complex data See also: dlmread, csvread,
     csvwrite, csv2cell, cell2csv.


>>



reply via email to

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