Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 454

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Simple File I/O - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Basic-Input-and-Output.html#Basic-Input-and-Output" title="Basic Input and Output">
<link rel="prev" href="Terminal-Input.html#Terminal-Input" title="Terminal Input">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Simple-File-I%2fO"></a>
<a name="Simple-File-I_002fO"></a>
<p>
Previous:&nbsp;<a rel="previous" accesskey="p" href="Terminal-Input.html#Terminal-Input">Terminal Input</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Basic-Input-and-Output.html#Basic-Input-and-Output">Basic Input and Output</a>
<hr>
</div>

<h4 class="subsection">14.1.3 Simple File I/O</h4>

<p><a name="index-saving-data-905"></a><a name="index-loading-data-906"></a>The <code>save</code> and <code>load</code> commands allow data to be written to and
read from disk files in various formats.  The default format of files
written by the <code>save</code> command can be controlled using the functions
<code>default_save_options</code> and <code>save_precision</code>.

   <p>As an example the following code creates a 3-by-3 matrix and saves it
to the file &lsquo;<samp><span class="samp">myfile.mat</span></samp>&rsquo;.

<pre class="example">     A = [ 1:3; 4:6; 7:9 ];
     save myfile.mat A
</pre>
   <p>Once one or more variables have been saved to a file, they can be
read into memory using the <code>load</code> command.

<pre class="example">     load myfile.mat
     A
          -| A =
          -|
          -|    1   2   3
          -|    4   5   6
          -|    7   8   9
</pre>
   <!-- save src/load-save.cc -->
   <p><a name="doc_002dsave"></a>

<div class="defun">
&mdash; Command:  <b>save</b><var> file<a name="index-save-907"></a></var><br>
&mdash; Command:  <b>save</b><var> options file<a name="index-save-908"></a></var><br>
&mdash; Command:  <b>save</b><var> options file v1 v2 <small class="dots">...</small><a name="index-save-909"></a></var><br>
&mdash; Command:  <b>save</b><var> options file -struct STRUCT f1 f2 <small class="dots">...</small><a name="index-save-910"></a></var><br>
<blockquote><p>Save the named variables <var>v1</var>, <var>v2</var>, <small class="dots">...</small>, in the file
<var>file</var>.  The special filename &lsquo;<samp><span class="samp">-</span></samp>&rsquo; may be used to write
output to the terminal.  If no variable names are listed, Octave saves
all the variables in the current scope.  Otherwise, full variable names or
pattern syntax can be used to specify the variables to save. 
If the <samp><span class="option">-struct</span></samp> modifier is used, fields <var>f1</var> <var>f2</var> <small class="dots">...</small>
of the scalar structure <var>STRUCT</var> are saved as if they were variables
with corresponding names. 
Valid options for the <code>save</code> command are listed in the following table. 
Options that modify the output format override the format specified by
<code>default_save_options</code>.

        <p>If save is invoked using the functional form

     <pre class="example">          save ("-option1", ..., "file", "v1", ...)
</pre>
        <p class="noindent">then the <var>options</var>, <var>file</var>, and variable name arguments
(<var>v1</var>, <small class="dots">...</small>) must be specified as character strings.

          <dl>
<dt><code>-append</code><dd>Append to the destination instead of overwriting.

          <br><dt><code>-ascii</code><dd>Save a single matrix in a text file without header or any other information.

          <br><dt><code>-binary</code><dd>Save the data in Octave's binary data format.

          <br><dt><code>-float-binary</code><dd>Save the data in Octave's binary data format but only using single
precision.  Only use this format if you know that all the
values to be saved can be represented in single precision.

          <br><dt><code>-hdf5</code><dd>Save the data in <span class="sc">hdf5</span> format. 
(HDF5 is a free, portable binary format developed by the National
Center for Supercomputing Applications at the University of Illinois.) 
This format is only available if Octave was built with a link to the
<span class="sc">hdf5</span> libraries.

          <br><dt><code>-float-hdf5</code><dd>Save the data in <span class="sc">hdf5</span> format but only using single precision. 
Only use this format if you know that all the
values to be saved can be represented in single precision.

          <br><dt><code>-V7</code><dt><code>-v7</code><dt><code>-7</code><dt><code>-mat7-binary</code><dd>Save the data in <span class="sc">matlab</span>'s v7 binary data format.

          <br><dt><code>-V6</code><dt><code>-v6</code><dt><code>-6</code><dt><code>-mat</code><dt><code>-mat-binary</code><dd>Save the data in <span class="sc">matlab</span>'s v6 binary data format.

          <br><dt><code>-V4</code><dt><code>-v4</code><dt><code>-4</code><dt><code>-mat4-binary</code><dd>Save the data in the binary format written by <span class="sc">matlab</span> version 4.

          <br><dt><code>-text</code><dd>Save the data in Octave's text data format.  (default).

          <br><dt><code>-zip</code><dt><code>-z</code><dd>Use the gzip algorithm to compress the file.  This works equally on files
that are compressed with gzip outside of octave, and gzip can equally be
used to convert the files for backward compatibility. 
This option is only available if Octave was built with a link to the zlib
libraries. 
</dl>

        <p>The list of variables to save may use wildcard patterns containing
the following special characters:
          <dl>
<dt><code>?</code><dd>Match any single character.

          <br><dt><code>*</code><dd>Match zero or more characters.

          <br><dt><code>[ </code><var>list</var><code> ]</code><dd>Match the list of characters specified by <var>list</var>.  If the first
character is <code>!</code> or <code>^</code>, match all characters except those
specified by <var>list</var>.  For example, the pattern <code>[a-zA-Z]</code> will
match all lower and uppercase alphabetic characters.

          <p>Wildcards may also be used in the field name specifications when using
the <samp><span class="option">-struct</span></samp> modifier (but not in the struct name itself).

        </dl>

        <p>Except when using the <span class="sc">matlab</span> binary data file format or the
&lsquo;<samp><span class="samp">-ascii</span></samp>&rsquo; format, saving global
variables also saves the global status of the variable.  If the variable
is restored at a later time using &lsquo;<samp><span class="samp">load</span></samp>&rsquo;, it will be restored as a
global variable.

        <p>The command

     <pre class="example">          save -binary data a b*
</pre>
        <p class="noindent">saves the variable &lsquo;<samp><span class="samp">a</span></samp>&rsquo; and all variables beginning with &lsquo;<samp><span class="samp">b</span></samp>&rsquo; to
the file <samp><span class="file">data</span></samp> in Octave's binary format. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dload.html#doc_002dload">load</a>, <a href="doc_002ddefault_005fsave_005foptions.html#doc_002ddefault_005fsave_005foptions">default_save_options</a>, <a href="doc_002dsave_005fheader_005fformat_005fstring.html#doc_002dsave_005fheader_005fformat_005fstring">save_header_format_string</a>, <a href="doc_002ddlmread.html#doc_002ddlmread">dlmread</a>, <a href="doc_002dcsvread.html#doc_002dcsvread">csvread</a>, <a href="doc_002dfread.html#doc_002dfread">fread</a>. 
</p></blockquote></div>

<!-- load src/load-save.cc -->
   <p><a name="doc_002dload"></a>

<div class="defun">
&mdash; Command:  <b>load</b><var> file<a name="index-load-911"></a></var><br>
&mdash; Command:  <b>load</b><var> options file<a name="index-load-912"></a></var><br>
&mdash; Command:  <b>load</b><var> options file v1 v2 <small class="dots">...</small><a name="index-load-913"></a></var><br>
&mdash; Command: S = <b>load</b> (<var>"options", "file", "v1", "v2", <small class="dots">...</small></var>)<var><a name="index-load-914"></a></var><br>
&mdash; Command:  <b>load</b><var> file options<a name="index-load-915"></a></var><br>
&mdash; Command:  <b>load</b><var> file options v1 v2 <small class="dots">...</small><a name="index-load-916"></a></var><br>
&mdash; Command: S = <b>load</b> (<var>"file", "options", "v1", "v2", <small class="dots">...</small></var>)<var><a name="index-load-917"></a></var><br>
<blockquote><p>Load the named variables <var>v1</var>, <var>v2</var>, <small class="dots">...</small>, from the file
<var>file</var>.  If no variables are specified then all variables found in the
file will be loaded.  As with <code>save</code>, the list of variables to extract
can be full names or use a pattern syntax.  The format of the file is
automatically detected but may be overridden by supplying the appropriate
option.

        <p>If load is invoked using the functional form

     <pre class="example">          load ("-option1", ..., "file", "v1", ...)
</pre>
        <p class="noindent">then the <var>options</var>, <var>file</var>, and variable name arguments
(<var>v1</var>, <small class="dots">...</small>) must be specified as character strings.

        <p>If a variable that is not marked as global is loaded from a file when a
global symbol with the same name already exists, it is loaded in the
global symbol table.  Also, if a variable is marked as global in a file
and a local symbol exists, the local symbol is moved to the global
symbol table and given the value from the file.

        <p>If invoked with a single output argument, Octave returns data instead
of inserting variables in the symbol table.  If the data file contains
only numbers (TAB- or space-delimited columns), a matrix of values is
returned.  Otherwise, <code>load</code> returns a structure with members
 corresponding to the names of the variables in the file.

        <p>The <code>load</code> command can read data stored in Octave's text and
binary formats, and <span class="sc">matlab</span>'s binary format.  If compiled with zlib
support, it can also load gzip-compressed files.  It will automatically
detect the type of file and do conversion from different floating point
formats (currently only IEEE big and little endian, though other formats
may be added in the future).

        <p>Valid options for <code>load</code> are listed in the following table.

          <dl>
<dt><code>-force</code><dd>This option is accepted for backward compatibility but is ignored. 
Octave now overwrites variables currently in memory with
those of the same name found in the file.

          <br><dt><code>-ascii</code><dd>Force Octave to assume the file contains columns of numbers in text format
without any header or other information.  Data in the file will be loaded
as a single numeric matrix with the name of the variable derived from the
name of the file.

          <br><dt><code>-binary</code><dd>Force Octave to assume the file is in Octave's binary format.

          <br><dt><code>-hdf5</code><dd>Force Octave to assume the file is in <span class="sc">hdf5</span> format. 
(<span class="sc">hdf5</span> is a free, portable binary format developed by the National
Center for Supercomputing Applications at the University of Illinois.) 
Note that Octave can read <span class="sc">hdf5</span> files not created by itself, but may
skip some datasets in formats that it cannot support.  This format is
only available if Octave was built with a link to the <span class="sc">hdf5</span> libraries.

          <br><dt><code>-import</code><dd>This option is accepted for backward compatibility but is ignored. 
Octave can now support multi-dimensional HDF data and automatically
modifies variable names if they are invalid Octave identifiers.

          <br><dt><code>-mat</code><dt><code>-mat-binary</code><dt><code>-6</code><dt><code>-v6</code><dt><code>-7</code><dt><code>-v7</code><dd>Force Octave to assume the file is in <span class="sc">matlab</span>'s version 6 or 7 binary
format.

          <br><dt><code>-mat4-binary</code><dt><code>-4</code><dt><code>-v4</code><dt><code>-V4</code><dd>Force Octave to assume the file is in the binary format written by
<span class="sc">matlab</span> version 4.

          <br><dt><code>-text</code><dd>Force Octave to assume the file is in Octave's text format. 
</dl>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dsave.html#doc_002dsave">save</a>, <a href="doc_002ddlmwrite.html#doc_002ddlmwrite">dlmwrite</a>, <a href="doc_002dcsvwrite.html#doc_002dcsvwrite">csvwrite</a>, <a href="doc_002dfwrite.html#doc_002dfwrite">fwrite</a>. 
</p></blockquote></div>

<!-- fileread scripts/io/fileread.m -->
   <p><a name="doc_002dfileread"></a>

<div class="defun">
&mdash; Function File: <var>str</var> = <b>fileread</b> (<var>filename</var>)<var><a name="index-fileread-918"></a></var><br>
<blockquote><p>Read the contents of <var>filename</var> and return it as a string. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfread.html#doc_002dfread">fread</a>, <a href="doc_002dtextread.html#doc_002dtextread">textread</a>, <a href="doc_002dsscanf.html#doc_002dsscanf">sscanf</a>. 
</p></blockquote></div>

   <p>There are three functions that modify the behavior of <code>save</code>.

<!-- default_save_options src/load-save.cc -->
   <p><a name="doc_002ddefault_005fsave_005foptions"></a>

<div class="defun">
&mdash; Built-in Function: <var>val</var> = <b>default_save_options</b> ()<var><a name="index-default_005fsave_005foptions-919"></a></var><br>
&mdash; Built-in Function: <var>old_val</var> = <b>default_save_options</b> (<var>new_val</var>)<var><a name="index-default_005fsave_005foptions-920"></a></var><br>
&mdash; Built-in Function:  <b>default_save_options</b> (<var>new_val, "local"</var>)<var><a name="index-default_005fsave_005foptions-921"></a></var><br>
<blockquote><p>Query or set the internal variable that specifies the default options
for the <code>save</code> command, and defines the default format. 
Typical values include <code>"-ascii"</code>, <code>"-text -zip"</code>. 
The default value is <samp><span class="option">-text</span></samp>.

        <p>When called from inside a function with the "local" option, the variable is
changed locally for the function and any subroutines it calls.  The original
variable value is restored when exiting the function. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dsave.html#doc_002dsave">save</a>. 
</p></blockquote></div>

<!-- save_precision src/ls-oct-ascii.cc -->
   <p><a name="doc_002dsave_005fprecision"></a>

<div class="defun">
&mdash; Built-in Function: <var>val</var> = <b>save_precision</b> ()<var><a name="index-save_005fprecision-922"></a></var><br>
&mdash; Built-in Function: <var>old_val</var> = <b>save_precision</b> (<var>new_val</var>)<var><a name="index-save_005fprecision-923"></a></var><br>
&mdash; Built-in Function:  <b>save_precision</b> (<var>new_val, "local"</var>)<var><a name="index-save_005fprecision-924"></a></var><br>
<blockquote><p>Query or set the internal variable that specifies the number of
digits to keep when saving data in text format.

        <p>When called from inside a function with the "local" option, the variable is
changed locally for the function and any subroutines it calls.  The original
variable value is restored when exiting the function. 
</p></blockquote></div>

<!-- save_header_format_string src/load-save.cc -->
   <p><a name="doc_002dsave_005fheader_005fformat_005fstring"></a>

<div class="defun">
&mdash; Built-in Function: <var>val</var> = <b>save_header_format_string</b> ()<var><a name="index-save_005fheader_005fformat_005fstring-925"></a></var><br>
&mdash; Built-in Function: <var>old_val</var> = <b>save_header_format_string</b> (<var>new_val</var>)<var><a name="index-save_005fheader_005fformat_005fstring-926"></a></var><br>
&mdash; Built-in Function:  <b>save_header_format_string</b> (<var>new_val, "local"</var>)<var><a name="index-save_005fheader_005fformat_005fstring-927"></a></var><br>
<blockquote><p>Query or set the internal variable that specifies the format
string used for the comment line written at the beginning of
text-format data files saved by Octave.  The format string is
passed to <code>strftime</code> and should begin with the character
&lsquo;<samp><span class="samp">#</span></samp>&rsquo; and contain no newline characters.  If the value of
<code>save_header_format_string</code> is the empty string,
the header comment is omitted from text-format data files.  The
default value is
<!-- Set example in small font to prevent overfull line -->

     <pre class="smallexample">          "# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z &lt;USER@HOST&gt;"
</pre>
        <p>When called from inside a function with the "local" option, the variable is
changed locally for the function and any subroutines it calls.  The original
variable value is restored when exiting the function. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrftime.html#doc_002dstrftime">strftime</a>, <a href="doc_002dsave.html#doc_002dsave">save</a>. 
</p></blockquote></div>

<!-- native_float_format src/sysdep.cc -->
   <p><a name="doc_002dnative_005ffloat_005fformat"></a>

<div class="defun">
&mdash; Built-in Function:  <b>native_float_format</b> ()<var><a name="index-native_005ffloat_005fformat-928"></a></var><br>
<blockquote><p>Return the native floating point format as a string
</p></blockquote></div>

   <p>It is possible to write data to a file in a similar way to the
<code>disp</code> function for writing data to the screen.  The <code>fdisp</code>
works just like <code>disp</code> except its first argument is a file pointer
as created by <code>fopen</code>.  As an example, the following code writes
to data &lsquo;<samp><span class="samp">myfile.txt</span></samp>&rsquo;.

<pre class="example">     fid = fopen ("myfile.txt", "w");
     fdisp (fid, "3/8 is ");
     fdisp (fid, 3/8);
     fclose (fid);
</pre>
   <p class="noindent">See <a href="Opening-and-Closing-Files.html#Opening-and-Closing-Files">Opening and Closing Files</a>, for details on how to use <code>fopen</code>
and <code>fclose</code>.

<!-- fdisp src/pr-output.cc -->
   <p><a name="doc_002dfdisp"></a>

<div class="defun">
&mdash; Built-in Function:  <b>fdisp</b> (<var>fid, x</var>)<var><a name="index-fdisp-929"></a></var><br>
<blockquote><p>Display the value of <var>x</var> on the stream <var>fid</var>.  For example:

     <pre class="example">          fdisp (stdout, "The value of pi is:"), fdisp (stdout, pi)
          
               -| the value of pi is:
               -| 3.1416
</pre>
        <p class="noindent">Note that the output from <code>fdisp</code> always ends with a newline. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddisp.html#doc_002ddisp">disp</a>. 
</p></blockquote></div>

   <p>Octave can also read and write matrices text files such as comma
separated lists.

<!-- dlmwrite scripts/io/dlmwrite.m -->
   <p><a name="doc_002ddlmwrite"></a>

<div class="defun">
&mdash; Function File:  <b>dlmwrite</b> (<var>file, M</var>)<var><a name="index-dlmwrite-930"></a></var><br>
&mdash; Function File:  <b>dlmwrite</b> (<var>file, M, delim, r, c</var>)<var><a name="index-dlmwrite-931"></a></var><br>
&mdash; Function File:  <b>dlmwrite</b> (<var>file, M, key, val <small class="dots">...</small></var>)<var><a name="index-dlmwrite-932"></a></var><br>
&mdash; Function File:  <b>dlmwrite</b> (<var>file, M, "-append", <small class="dots">...</small></var>)<var><a name="index-dlmwrite-933"></a></var><br>
&mdash; Function File:  <b>dlmwrite</b> (<var>fid, <small class="dots">...</small></var>)<var><a name="index-dlmwrite-934"></a></var><br>
<blockquote><p>Write the matrix <var>M</var> to the named file using delimiters.

        <p><var>file</var> should be a file name or writable file ID given by <code>fopen</code>.

        <p>The parameter <var>delim</var> specifies the delimiter to use to separate
values on a row.

        <p>The value of <var>r</var> specifies the number of delimiter-only lines to
add to the start of the file.

        <p>The value of <var>c</var> specifies the number of delimiters to prepend to
each line of data.

        <p>If the argument <code>"-append"</code> is given, append to the end of
<var>file</var>.

        <p>In addition, the following keyword value pairs may appear at the end
of the argument list:

          <dl>
<dt>"append"<dd>Either &lsquo;<samp><span class="samp">"on"</span></samp>&rsquo; or &lsquo;<samp><span class="samp">"off"</span></samp>&rsquo;.  See &lsquo;<samp><span class="samp">"-append"</span></samp>&rsquo; above.

          <br><dt>"delimiter"<dd>See <var>delim</var> above.

          <br><dt>"newline"<dd>The character(s) to use to separate each row.  Three special cases
exist for this option.  &lsquo;<samp><span class="samp">"unix"</span></samp>&rsquo; is changed into "\n",
&lsquo;<samp><span class="samp">"pc"</span></samp>&rsquo; is changed into "\r\n", and &lsquo;<samp><span class="samp">"mac"</span></samp>&rsquo; is changed
into "\r".  Other values for this option are kept as is.

          <br><dt>"roffset"<dd>See <var>r</var> above.

          <br><dt>"coffset"<dd>See <var>c</var> above.

          <br><dt>"precision"<dd>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. 
</dl>

     <pre class="example">          dlmwrite ("file.csv", reshape (1:16, 4, 4));
</pre>
        <pre class="example">          dlmwrite ("file.tex", a, "delimiter", "&amp;", "newline", "\\n")
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddlmread.html#doc_002ddlmread">dlmread</a>, <a href="doc_002dcsvread.html#doc_002dcsvread">csvread</a>, <a href="doc_002dcsvwrite.html#doc_002dcsvwrite">csvwrite</a>. 
</p></blockquote></div>

<!-- dlmread src/DLD-FUNCTIONS/dlmread.cc -->
   <p><a name="doc_002ddlmread"></a>

<div class="defun">
&mdash; Loadable Function: <var>data</var> = <b>dlmread</b> (<var>file</var>)<var><a name="index-dlmread-935"></a></var><br>
&mdash; Loadable Function: <var>data</var> = <b>dlmread</b> (<var>file, sep</var>)<var><a name="index-dlmread-936"></a></var><br>
&mdash; Loadable Function: <var>data</var> = <b>dlmread</b> (<var>file, sep, r0, c0</var>)<var><a name="index-dlmread-937"></a></var><br>
&mdash; Loadable Function: <var>data</var> = <b>dlmread</b> (<var>file, sep, range</var>)<var><a name="index-dlmread-938"></a></var><br>
&mdash; Loadable Function: <var>data</var> = <b>dlmread</b> (<var><small class="dots">...</small>, "emptyvalue", EMPTYVAL</var>)<var><a name="index-dlmread-939"></a></var><br>
<blockquote><p>Read the matrix <var>data</var> from a text file.  If not defined the separator
between fields is determined from the file itself.  Otherwise the
separation character is defined by <var>sep</var>.

        <p>Given two scalar arguments <var>r0</var> and <var>c0</var>, these define the starting
row and column of the data to be read.  These values are indexed from zero,
such that the first row corresponds to an index of zero.

        <p>The <var>range</var> parameter may be a 4-element vector containing the upper
left and lower right corner <code>[</code><var>R0</var><code>,</code><var>C0</var><code>,</code><var>R1</var><code>,</code><var>C1</var><code>]</code>
where the lowest index value is zero.  Alternatively, a spreadsheet style
range such as 'A2..Q15' or 'T1:AA5' can be used.  The lowest alphabetical
index 'A' refers to the first column.  The lowest row index is 1.

        <p><var>file</var> should be a file name or file id given by <code>fopen</code>.  In the
latter case, the file is read until end of file is reached.

        <p>The "emptyvalue" option may be used to specify the value used to fill empty
fields.  The default is zero. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcsvread.html#doc_002dcsvread">csvread</a>, <a href="doc_002dtextscan.html#doc_002dtextscan">textscan</a>, <a href="doc_002dtextread.html#doc_002dtextread">textread</a>, <a href="doc_002ddlmwrite.html#doc_002ddlmwrite">dlmwrite</a>. 
</p></blockquote></div>

<!-- csvwrite scripts/io/csvwrite.m -->
   <p><a name="doc_002dcsvwrite"></a>

<div class="defun">
&mdash; Function File:  <b>csvwrite</b> (<var>filename, x</var>)<var><a name="index-csvwrite-940"></a></var><br>
&mdash; Function File:  <b>csvwrite</b> (<var>filename, x, dlm_opts</var>)<var><a name="index-csvwrite-941"></a></var><br>
<blockquote><p>Write the matrix <var>x</var> to the file <var>filename</var> in
comma-separated-value<!-- /@w --> format.

        <p>This function is equivalent to

     <pre class="example">          dlmwrite (<var>filename</var>, <var>x</var>, ",", ...)
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcsvread.html#doc_002dcsvread">csvread</a>, <a href="doc_002ddlmwrite.html#doc_002ddlmwrite">dlmwrite</a>, <a href="doc_002ddlmread.html#doc_002ddlmread">dlmread</a>. 
</p></blockquote></div>

<!-- csvread scripts/io/csvread.m -->
   <p><a name="doc_002dcsvread"></a>

<div class="defun">
&mdash; Function File: <var>x</var> = <b>csvread</b> (<var>filename</var>)<var><a name="index-csvread-942"></a></var><br>
&mdash; Function File: <var>x</var> = <b>csvread</b> (<var>filename, dlm_opts</var>)<var><a name="index-csvread-943"></a></var><br>
<blockquote><p>Read the comma-separated-value file <var>filename</var> into the matrix <var>x</var>.

        <p>This function is equivalent to

     <pre class="example">          <var>x</var> = dlmread (<var>filename</var>, "," , ...)
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcsvwrite.html#doc_002dcsvwrite">csvwrite</a>, <a href="doc_002ddlmread.html#doc_002ddlmread">dlmread</a>, <a href="doc_002ddlmwrite.html#doc_002ddlmwrite">dlmwrite</a>. 
</p></blockquote></div>

   <p>Formatted data from can be read from, or written to, text files as well.

<!-- textread scripts/io/textread.m -->
   <p><a name="doc_002dtextread"></a>

<div class="defun">
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>textread</b> (<var>filename</var>)<var><a name="index-textread-944"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>textread</b> (<var>filename, format</var>)<var><a name="index-textread-945"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>textread</b> (<var>filename, format, n</var>)<var><a name="index-textread-946"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>textread</b> (<var>filename, format, prop1, value1, <small class="dots">...</small></var>)<var><a name="index-textread-947"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>textread</b> (<var>filename, format, n, prop1, value1, <small class="dots">...</small></var>)<var><a name="index-textread-948"></a></var><br>
<blockquote><p>Read data from a text file.

        <p>The file <var>filename</var> is read and parsed according to <var>format</var>.  The
function behaves like <code>strread</code> except it works by parsing a file
instead of a string.  See the documentation of <code>strread</code> for details.

        <p>In addition to the options supported by <code>strread</code>, this function
supports two more:

          <ul>
<li>"headerlines":
The first <var>value</var> number of lines of <var>filename</var> are skipped.

          <li>"endofline":
Specify a single character or "\r\n".  If no value is given, it will be
inferred from the file.  If set to "" (empty string) EOLs are ignored as
delimiters. 
</ul>

        <p>The optional input <var>n</var> specifes the number of times to use
<var>format</var> when parsing, i.e., the format repeat count.

     <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrread.html#doc_002dstrread">strread</a>, <a href="doc_002dload.html#doc_002dload">load</a>, <a href="doc_002ddlmread.html#doc_002ddlmread">dlmread</a>, <a href="doc_002dfscanf.html#doc_002dfscanf">fscanf</a>, <a href="doc_002dtextscan.html#doc_002dtextscan">textscan</a>. 
</p></blockquote></div>

<!-- textscan scripts/io/textscan.m -->
   <p><a name="doc_002dtextscan"></a>

<div class="defun">
&mdash; Function File: <var>C</var> = <b>textscan</b> (<var>fid, format</var>)<var><a name="index-textscan-949"></a></var><br>
&mdash; Function File: <var>C</var> = <b>textscan</b> (<var>fid, format, n</var>)<var><a name="index-textscan-950"></a></var><br>
&mdash; Function File: <var>C</var> = <b>textscan</b> (<var>fid, format, param, value, <small class="dots">...</small></var>)<var><a name="index-textscan-951"></a></var><br>
&mdash; Function File: <var>C</var> = <b>textscan</b> (<var>fid, format, n, param, value, <small class="dots">...</small></var>)<var><a name="index-textscan-952"></a></var><br>
&mdash; Function File: <var>C</var> = <b>textscan</b> (<var>str, <small class="dots">...</small></var>)<var><a name="index-textscan-953"></a></var><br>
&mdash; Function File: [<var>C</var>, <var>position</var>] = <b>textscan</b> (<var>fid, <small class="dots">...</small></var>)<var><a name="index-textscan-954"></a></var><br>
<blockquote><p>Read data from a text file or string.

        <p>The file associated with <var>fid</var> is read and parsed according to
<var>format</var>.  The function behaves like <code>strread</code> except it works by
parsing a file instead of a string.  See the documentation of
<code>strread</code> for details.

        <p>In addition to the options supported by
<code>strread</code>, this function supports a few more:

          <ul>
<li>"collectoutput":
A value of 1 or true instructs textscan to concatenate consecutive columns
of the same class in the output cell array.  A value of 0 or false (default)
leaves output in distinct columns.

          <li>"endofline":
Specify "\r", "\n" or "\r\n" (for CR, LF, or CRLF).  If no value is given,
it will be inferred from the file.  If set to "" (empty string) EOLs are
ignored as delimiters and added to whitespace.

          <li>"headerlines":
The first <var>value</var> number of lines of <var>fid</var> are skipped.

          <li>"returnonerror":
If set to numerical 1 or true (default), return normally when read errors
have been encountered.  If set to 0 or false, return an error and no data. 
</ul>

        <p>The optional input <var>n</var> specifes the number of times to use
<var>format</var> when parsing, i.e., the format repeat count.

        <p>The output <var>C</var> is a cell array whose length is given by the number
of format specifiers.

        <p>The second output, <var>position</var>, provides the position, in characters,
from the beginning of the file.

     <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddlmread.html#doc_002ddlmread">dlmread</a>, <a href="doc_002dfscanf.html#doc_002dfscanf">fscanf</a>, <a href="doc_002dload.html#doc_002dload">load</a>, <a href="doc_002dstrread.html#doc_002dstrread">strread</a>, <a href="doc_002dtextread.html#doc_002dtextread">textread</a>. 
</p></blockquote></div>

<ul class="menu">
<li><a accesskey="1" href="Saving-Data-on-Unexpected-Exits.html#Saving-Data-on-Unexpected-Exits">Saving Data on Unexpected Exits</a>
</ul>

   </body></html>