1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>FreeMat: LOAD Load Variables From A File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">FreeMat
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('io_load.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">LOAD Load Variables From A File </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Section: <a class="el" href="sec_io.html">Input/Ouput Functions</a> </p>
<h1><a class="anchor" id="Usage"></a>
Usage</h1>
<p>Loads a set of variables from a file in a machine independent format. The <code>load</code> function takes one argument: </p>
<pre class="fragment"> load filename,
</pre><p> or alternately, </p>
<pre class="fragment"> load('filename')
</pre><p> This command is the companion to <code>save</code>. It loads the contents of the file generated by <code>save</code> back into the current context. Global and persistent variables are also loaded and flagged appropriately. By default, FreeMat assumes that files that end in a <code>.mat</code> or <code>.MAT</code> extension are MATLAB-formatted files. Also, FreeMat assumes that files that end in <code>.txt</code> or <code>.TXT</code> are ASCII files. For other filenames, FreeMat first tries to open the file as a FreeMat binary format file (as created by the <code>save</code> function). If the file fails to open as a FreeMat binary file, then FreeMat attempts to read it as an ASCII file.</p>
<p>You can force FreeMat to assume a particular format for the file by using alternate forms of the <code>load</code> command. In particular, </p>
<pre class="fragment"> load -ascii filename
</pre><p> will load the data in file <code>filename</code> as an ASCII file (space delimited numeric text) loaded into a single variable in the current workspace with the name <code>filename</code> (without the extension).</p>
<p>For MATLAB-formatted data files, you can use </p>
<pre class="fragment"> load -mat filename
</pre><p> which forces FreeMat to assume that <code>filename</code> is a MAT-file, regardless of the extension on the filename.</p>
<p>You can also specify which variables to load from a file (not from an ASCII file - only single 2-D variables can be successfully saved and retrieved from ASCII files) using the additional syntaxes of the <code>load</code> command. In particular, you can specify a set of variables to load by name </p>
<pre class="fragment"> load filename Var_1 Var_2 Var_3 ...
</pre><p> where <code>Var_n</code> is the name of a variable to load from the file. Alternately, you can use the regular expression syntax </p>
<pre class="fragment"> load filename -regexp expr_1 expr_2 expr_3 ...
</pre><p> where <code>expr_n</code> is a regular expression (roughly as expected by <code>regexp</code>). Note that a simpler regular expression mechanism is used for this syntax than the full mechanism used by the <code>regexp</code> command.</p>
<p>Finally, you can use <code>load</code> to create a variable containing the contents of the file, instead of automatically inserting the variables into the curent workspace. For this form of <code>load</code> you must use the function syntax, and capture the output: </p>
<pre class="fragment"> V = load('arg1','arg2',...)
</pre><p> which returns a structure <code>V</code> with one field for each variable retrieved from the file. For ASCII files, <code>V</code> is a double precision matrix.</p>
<h1><a class="anchor" id="Example"></a>
Example</h1>
<p>Here is a simple example of <code>save</code>/<code>load</code>. First, we save some variables to a file.</p>
<pre class="fragment">--> D = {1,5,'hello'};
--> s = 'test string';
--> x = randn(512,1);
--> z = zeros(512);
--> who
Variable Name Type Flags Size
D cell [1x3]
s char [1x11]
x double [512x1]
z double [512x512]
--> save loadsave.dat
</pre><p>Next, we clear the variables, and then load them back from the file.</p>
<pre class="fragment">--> clear D s x z
--> who
Variable Name Type Flags Size
ans double [0x0]
--> load loadsave.dat
--> who
Variable Name Type Flags Size
D cell [1x3]
ans double [0x0]
s char [1x11]
x double [512x1]
z double [512x512]
</pre> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="index.html">FreeMat Documentation</a></li><li class="navelem"><a class="el" href="sec_io.html">Input/Ouput Functions</a></li>
<li class="footer">Generated on Thu Jul 25 2013 17:17:38 for FreeMat by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.1 </li>
</ul>
</div>
</body>
</html>
|