<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://eclr.humanities.manchester.ac.uk/index.php?action=history&amp;feed=atom&amp;title=SavingData</id>
		<title>SavingData - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://eclr.humanities.manchester.ac.uk/index.php?action=history&amp;feed=atom&amp;title=SavingData"/>
		<link rel="alternate" type="text/html" href="http://eclr.humanities.manchester.ac.uk/index.php?title=SavingData&amp;action=history"/>
		<updated>2026-05-11T11:36:10Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.1</generator>

	<entry>
		<id>http://eclr.humanities.manchester.ac.uk/index.php?title=SavingData&amp;diff=294&amp;oldid=prev</id>
		<title>Admin at 14:28, 25 September 2012</title>
		<link rel="alternate" type="text/html" href="http://eclr.humanities.manchester.ac.uk/index.php?title=SavingData&amp;diff=294&amp;oldid=prev"/>
				<updated>2012-09-25T14:28:42Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 14:28, 25 September 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l66&quot; &gt;Line 66:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 66:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Publish Code and Results =&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Publish Code and Results =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Sometimes it is useful to have your code and your calculated results in one place. MATLAB provides an extremely useful functionality to achieve this, namely to &amp;amp;quot;publish&amp;amp;quot; your code. This interlaces your code with the output produced by your code. How to do this is best understood by watching the following &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;[&lt;/del&gt;[http://www.youtube.com/watch?v=f1pzVW71rLI clip&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;]&lt;/del&gt;].&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Sometimes it is useful to have your code and your calculated results in one place. MATLAB provides an extremely useful functionality to achieve this, namely to &amp;amp;quot;publish&amp;amp;quot; your code. This interlaces your code with the output produced by your code. How to do this is best understood by watching the following [http://www.youtube.com/watch?v=f1pzVW71rLI clip].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;= Footnotes =&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;references /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;references /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://eclr.humanities.manchester.ac.uk/index.php?title=SavingData&amp;diff=293&amp;oldid=prev</id>
		<title>Admin: /* Publish Code and Results */</title>
		<link rel="alternate" type="text/html" href="http://eclr.humanities.manchester.ac.uk/index.php?title=SavingData&amp;diff=293&amp;oldid=prev"/>
				<updated>2012-09-25T14:27:43Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Publish Code and Results&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 14:27, 25 September 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l66&quot; &gt;Line 66:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 66:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Publish Code and Results =&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Publish Code and Results =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Sometimes it is useful to have your code and your calculated results in one place. MATLAB provides an extremely useful functionality to achieve this, namely to &amp;amp;quot;publish&amp;amp;quot; your code. This interlaces your code with the output produced by your code. How to do this is best understood by watching the following [[http://www.youtube.com/watch?v=f1pzVW71rLI&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;|&lt;/del&gt;clip]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Sometimes it is useful to have your code and your calculated results in one place. MATLAB provides an extremely useful functionality to achieve this, namely to &amp;amp;quot;publish&amp;amp;quot; your code. This interlaces your code with the output produced by your code. How to do this is best understood by watching the following [[http://www.youtube.com/watch?v=f1pzVW71rLI clip]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;references /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;references /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://eclr.humanities.manchester.ac.uk/index.php?title=SavingData&amp;diff=292&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;= Saving Data and Results =  When you do any econometric work you will have some results to show for. These may be estimated parameters, residuals, simulated data, etc. We wil...&quot;</title>
		<link rel="alternate" type="text/html" href="http://eclr.humanities.manchester.ac.uk/index.php?title=SavingData&amp;diff=292&amp;oldid=prev"/>
				<updated>2012-09-25T14:25:34Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Saving Data and Results =  When you do any econometric work you will have some results to show for. These may be estimated parameters, residuals, simulated data, etc. We wil...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Saving Data and Results =&lt;br /&gt;
&lt;br /&gt;
When you do any econometric work you will have some results to show for. These may be estimated parameters, residuals, simulated data, etc. We will have to discuss how you save these results. This is especially important if your computations are lengthy, as just repeating the calculations may take too long. In general there are three ways in which you can save results.&lt;br /&gt;
&lt;br /&gt;
# Save the MATLAB workspace or elements thereof. You will need MATLAB to access the results.&lt;br /&gt;
# Save matrices in an EXCEL file. Obviously you will need EXCEL (or any other spreadsheet software) to access the saved results. This may be of advantage if you are planning to report results via EXCEL tables.&lt;br /&gt;
# Save some output in a text file. You can the access these results with any software that can read text.&lt;br /&gt;
&lt;br /&gt;
From the above it is obvious that your decision should be based on how we will be able to read the results afterwards. To say this from the outset, the preferred method is going to be the one which saves the MATLAB workspace. The other two options have so many restrictions that they should only be contemplated when you know that you do not have access to MATLAB and need to read the results.&lt;br /&gt;
&lt;br /&gt;
= Save MATLAB workspace =&lt;br /&gt;
&lt;br /&gt;
It was discussed in the introductory module that the MATLAB workspace saves all your variables you create in the course of one program. At any stage in the code you can save that entire workspace using the following simple command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;save results&amp;lt;/source&amp;gt;&lt;br /&gt;
Doing this will create a new file in your current directory that is called &amp;lt;source enclose=none&amp;gt;results.mat&amp;lt;/source&amp;gt;. This is a MATLAB specific format. Next time you open MATLAB and you execute&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;load results&amp;lt;/source&amp;gt;&lt;br /&gt;
your MATLAB workspace will be populated with all the variables that were saved in &amp;lt;source enclose=none&amp;gt;results.mat&amp;lt;/source&amp;gt; and they have exactly the same names as they used to have previously. You can use the &amp;lt;source enclose=none&amp;gt;load&amp;lt;/source&amp;gt; command in another piece of code and in this way you can use the elements in &amp;lt;source enclose=none&amp;gt;results.mat&amp;lt;/source&amp;gt; for further calculations.&lt;br /&gt;
&lt;br /&gt;
You will soon learn that in the course of a reasonably complex program you will accumulate a big number of variables, many of which you are not really interested in, but were needed for preliminary calculations. If you use the load command as described above, all these variables will also appear in &amp;lt;source enclose=none&amp;gt;results.mat&amp;lt;/source&amp;gt;. It will often be useful to be somewhat more selective and clearly specify which of the many variables you have you actually want to save for posterity. Say the variables &amp;lt;source enclose=none&amp;gt;x&amp;lt;/source&amp;gt;, &amp;lt;source enclose=none&amp;gt;y&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;z&amp;lt;/source&amp;gt; contain the results you want to save, then you should use the following command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;save results x y z&amp;lt;/source&amp;gt;&lt;br /&gt;
which saves these three variables in &amp;lt;source enclose=none&amp;gt;results.mat&amp;lt;/source&amp;gt; but nothing else. It is also useful to know that in that list of variables you can use a wildcard &amp;lt;source enclose=none&amp;gt;*&amp;lt;/source&amp;gt; character. Say you want to save the following five variables: &amp;lt;source enclose=none&amp;gt;x1&amp;lt;/source&amp;gt;, &amp;lt;source enclose=none&amp;gt;x2&amp;lt;/source&amp;gt;, &amp;lt;source enclose=none&amp;gt;x3&amp;lt;/source&amp;gt;, &amp;lt;source enclose=none&amp;gt;x4&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;x5&amp;lt;/source&amp;gt;, then you can achieve this with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;save results x*&amp;lt;/source&amp;gt;&lt;br /&gt;
= Output to EXCEL file =&lt;br /&gt;
&lt;br /&gt;
This method may be useful if you know that you will use the MATLAB results to create a Table in EXCEL. Let’s say you have two matrices which you want to store, &amp;lt;source enclose=none&amp;gt;res1&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;res2&amp;lt;/source&amp;gt;. You could, in a fairly straightforward way, store each matrix as their own EXCEL worksheet.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;xlswrite(&amp;#039;test.xlsx&amp;#039;, res1, &amp;#039;res1&amp;#039;);&lt;br /&gt;
xlswrite(&amp;#039;test.xlsx&amp;#039;, res2, &amp;#039;res2&amp;#039;);&amp;lt;/source&amp;gt;&lt;br /&gt;
The commands here have three inputs: &amp;lt;source enclose=none&amp;gt;xlswrite(’FILENAME.xlsx’, VARNAME, ’EXCELSHEETNAME’)&amp;lt;/source&amp;gt; where &amp;lt;source enclose=none&amp;gt;VARNAME&amp;lt;/source&amp;gt; is the MATLAB variable you want to save and &amp;lt;source enclose=none&amp;gt;EXCELSHEETNAME&amp;lt;/source&amp;gt; is the name you want to give to the EXCEL sheet that should store the variable. This will create an EXCEL file with two new sheets named &amp;amp;quot;res1&amp;amp;quot; and &amp;amp;quot;res2&amp;amp;quot; containing the matrices &amp;lt;source enclose=none&amp;gt;res1&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;res2&amp;lt;/source&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
You could also save the two matrices into the same spreadsheet, but then you need to be precise where on the spreadsheet you want to save each of the two. Also you should add names to the spreadsheet as you want to make sure that you keep track of which data come from which variable. Say the variable &amp;lt;source enclose=none&amp;gt;res1&amp;lt;/source&amp;gt; has dimension &amp;lt;math&amp;gt;(3\times2)&amp;lt;/math&amp;gt; and &amp;lt;source enclose=none&amp;gt;res2&amp;lt;/source&amp;gt; is a &amp;lt;math&amp;gt;(2\times4)&amp;lt;/math&amp;gt; matrix. Then you could do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;xlswrite(&amp;#039;test.xlsx&amp;#039;, {&amp;#039;res1&amp;#039;}, &amp;#039;Sheet1&amp;#039;, &amp;#039;A1:A1&amp;#039;);     % Saves Name&lt;br /&gt;
xlswrite(&amp;#039;test.xlsx&amp;#039;, res1, &amp;#039;Sheet1&amp;#039;, &amp;#039;A2:B4&amp;#039;);&lt;br /&gt;
xlswrite(&amp;#039;test.xlsx&amp;#039;, {&amp;#039;res2&amp;#039;}, &amp;#039;Sheet1&amp;#039;, &amp;#039;A6:A6&amp;#039;);     % Saves Name&lt;br /&gt;
xlswrite(&amp;#039;test.xlsx&amp;#039;, res2, &amp;#039;Sheet1&amp;#039;, &amp;#039;A7:D8&amp;#039;);&amp;lt;/source&amp;gt;&lt;br /&gt;
These lines contain two little novelties compared to the previous commands. Here &amp;lt;source enclose=none&amp;gt;xlswrite&amp;lt;/source&amp;gt; has a fourth input. This input specifies the cell range into which the variable is to be written. Say, in line 2 the cell reference is &amp;lt;source enclose=none&amp;gt;’A2:B4’&amp;lt;/source&amp;gt; which references the a &amp;lt;math&amp;gt;(3\times2)&amp;lt;/math&amp;gt; cell block in EXCEL, exactly the correct size for &amp;lt;source enclose=none&amp;gt;res1&amp;lt;/source&amp;gt;. In line 1 the second input into the &amp;lt;source enclose=none&amp;gt;xlswrite&amp;lt;/source&amp;gt; command is &amp;lt;source enclose=none&amp;gt;{’res1’}&amp;lt;/source&amp;gt;. This is not the variable res1, but a piece of text &amp;amp;quot;res1&amp;amp;quot; that is being written into cell A1.&lt;br /&gt;
&lt;br /&gt;
= Output to Text file =&lt;br /&gt;
&lt;br /&gt;
The least convenient way to save results is in a text file, a file that can be read by basically any text editor. In fact, the only reason you may want to do it is if you want to add written comments to your results. BUT, printing matrices to a text file is a bit of a nightmare (and will not be dealt with here. If you have big matrices, use one of the above techniques. Small matrices can be dealt with by treating each element as a scalar. The basic structure is as follows. You first open a file into which you want to write your results (see line 1 below). Then whenever you want to print something into that file you use the &amp;lt;source enclose=none&amp;gt;fprintf&amp;lt;/source&amp;gt; (for text and scalars). Let me present a piece of code and then explain how it works. The aim is to save the &amp;lt;math&amp;gt;(2\times1)&amp;lt;/math&amp;gt; vector &amp;lt;source enclose=none&amp;gt;res3&amp;lt;/source&amp;gt; and the scalar variables &amp;lt;source enclose=none&amp;gt;n&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;k&amp;lt;/source&amp;gt; to a text file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;fid = fopen(&amp;#039;test.txt&amp;#039;,&amp;#039;a&amp;#039;);&lt;br /&gt;
fprintf(fid,&amp;#039;Number of obs: %6.0f; Number of variables: %4.2f \n&amp;#039;, n, k);&lt;br /&gt;
fprintf(fid,&amp;#039;Estimated parameters: %8.4f %8.4f \n&amp;#039;,res3);&lt;br /&gt;
fclose(fid);&amp;lt;/source&amp;gt;&lt;br /&gt;
The output that is produced by this piece of code is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;Number of obs: 100; Number of variables: 3.00&lt;br /&gt;
Estimated parameters: 0.2578 12.5789&amp;lt;/source&amp;gt;&lt;br /&gt;
assuming that &amp;lt;math&amp;gt;n=100&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;k=3&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;res3=(0.2578\;12.5789)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The command in line 1 opens a text file called &amp;lt;source enclose=none&amp;gt;test.txt&amp;lt;/source&amp;gt; and for the remainder of the code gives it the name &amp;lt;source enclose=none&amp;gt;fid&amp;lt;/source&amp;gt;. We will use this name whenever we need to refer to this file. The second input into the &amp;lt;source enclose=none&amp;gt;fopen&amp;lt;/source&amp;gt; command, &amp;lt;source enclose=none&amp;gt;’a’&amp;lt;/source&amp;gt;, stands for append and means that, should this file already exist, you will add whatever you add to the end of the file. If you use &amp;lt;source enclose=none&amp;gt;’w’&amp;lt;/source&amp;gt; instead you will overwrite anything that is already in that file. Let’s briefly jump to the last line (Line 4), here the file &amp;lt;source enclose=none&amp;gt;fid&amp;lt;/source&amp;gt; is closed again. Inbetween these two lines you can print something into the file.&lt;br /&gt;
&lt;br /&gt;
This is done using the command &amp;lt;source enclose=none&amp;gt;fprintf&amp;lt;/source&amp;gt;. On first sight Lines 2 and 3 look like a mess&amp;lt;ref&amp;gt;For the full gory detail of what is happening here you should check &amp;lt;source enclose=none&amp;gt;doc fprintf&amp;lt;/source&amp;gt;. Here you will get the quick version&lt;br /&gt;
&amp;lt;/ref&amp;gt;. Let’s decipher what we can see here. The general command structure is &amp;lt;source enclose=none&amp;gt;fprintf(FileID,&amp;lt;/source&amp;gt;&amp;lt;source enclose=none&amp;gt;’text text VARREF1 text VARREF2 \n ’, VAR1, VAR2)&amp;lt;/source&amp;gt;. The first bit is straightforward. The command &amp;lt;source enclose=none&amp;gt;fprintf&amp;lt;/source&amp;gt; tells MATLAB to print something into a file and the first input &amp;lt;source enclose=none&amp;gt;FileID&amp;lt;/source&amp;gt; indicates which file that ought to be, &amp;lt;source enclose=none&amp;gt;test.txt&amp;lt;/source&amp;gt; in our case, or for MATLAB &amp;lt;source enclose=none&amp;gt;fid&amp;lt;/source&amp;gt; (from Line 1). Before we try to understand the second input (between the single quotation marks) we will go to the last two, &amp;lt;source enclose=none&amp;gt;n&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;k&amp;lt;/source&amp;gt;. They are the two MATLAB variables that are to be worked into the output. If you had more than two variables to be printed this list would be longer. So, now the complicated bit (and you will begin to understand why this is not really the preferred method), the second input. You can see some text but also the somewhat cryptic &amp;lt;source enclose=none&amp;gt;%6.0f&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;%4.2f&amp;lt;/source&amp;gt;. These bits have two functions. First, they tell MATLAB where, inbetween the remaining text, the variables &amp;lt;source enclose=none&amp;gt;n&amp;lt;/source&amp;gt; and &amp;lt;source enclose=none&amp;gt;k&amp;lt;/source&amp;gt; are to be printed. This bit always starts with a &amp;lt;source enclose=none&amp;gt;%&amp;lt;/source&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The second function is to tell MATLAB how to format the number. This one ends with a &amp;lt;source enclose=none&amp;gt;f&amp;lt;/source&amp;gt; which indicates that you fix where the decimal point goes. The number before the decimal point tells MATLAB how many characters it should reserve for the variable and the number after the decimal point indicates how many digits after the decimal point should be displayed. Check out &amp;lt;source enclose=none&amp;gt;doc fprintf&amp;lt;/source&amp;gt; for a discussion of all the different options or even better try a few options yourself. Lastly, the &amp;lt;source enclose=none&amp;gt;\n&amp;lt;/source&amp;gt; merely tells MATLAB to now switch to a new line.&lt;br /&gt;
&lt;br /&gt;
Command line 3 does basically exactly the same. You can see that there are two placeholders for MATLAB variables. This time, however, this is only followed by one MATLAB variable &amp;lt;source enclose=none&amp;gt;res3&amp;lt;/source&amp;gt;. But note that this variable has two elements and &amp;lt;source enclose=none&amp;gt;fprintf&amp;lt;/source&amp;gt; treats these two elements as if they were two different variables.&lt;br /&gt;
&lt;br /&gt;
= Publish Code and Results =&lt;br /&gt;
&lt;br /&gt;
Sometimes it is useful to have your code and your calculated results in one place. MATLAB provides an extremely useful functionality to achieve this, namely to &amp;amp;quot;publish&amp;amp;quot; your code. This interlaces your code with the output produced by your code. How to do this is best understood by watching the following [[http://www.youtube.com/watch?v=f1pzVW71rLI|clip]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>