<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172073</link>
    <title>MATLAB Central Newsreader - problem with a 'for' loop</title>
    <description>Feed for thread: problem with a 'for' loop</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 05 Jul 2008 13:20:03 -0400</pubDate>
      <title>problem with a 'for' loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172073#441289</link>
      <author>Francesco </author>
      <description>Hi everybody,&lt;br&gt;
I am trying, in a for loop over the index j to load .mat &lt;br&gt;
files (data_%d.mat) from an external hard drive E:\.&lt;br&gt;
My files are stored in the directory dir2 and I would like &lt;br&gt;
to load only variables var1 and var2 from the .mat file.&lt;br&gt;
I am trying to use this string, but it doesn't work...&lt;br&gt;
&lt;br&gt;
for j=1:N&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filename = num2str(j,'data_%d.mat');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;load(j,'E:\dir1\dir2\filename', 'var1','var2')&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
What am I doing wrong? Could you help me to write it &lt;br&gt;
correctly?&lt;br&gt;
Many thanks,&lt;br&gt;
Francesco</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jul 2008 15:13:01 -0400</pubDate>
      <title>Re: problem with a 'for' loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172073#441304</link>
      <author>Bruno Luong</author>
      <description>&quot;Francesco &quot; &amp;lt;fsarnari@maths.leeds.ac.uk&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g4nse3$gco$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi everybody,&lt;br&gt;
&amp;gt; I am trying, in a for loop over the index j to load .mat &lt;br&gt;
&amp;gt; files (data_%d.mat) from an external hard drive E:\.&lt;br&gt;
&amp;gt; My files are stored in the directory dir2 and I would like &lt;br&gt;
&amp;gt; to load only variables var1 and var2 from the .mat file.&lt;br&gt;
&amp;gt; I am trying to use this string, but it doesn't work...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for j=1:N&lt;br&gt;
&amp;gt;     filename = num2str(j,'data_%d.mat');&lt;br&gt;
&amp;gt;     load(j,'E:\dir1\dir2\filename', 'var1','var2')&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; What am I doing wrong? Could you help me to write it &lt;br&gt;
&lt;br&gt;
1. 'E:\dir1\dir2\filename'&lt;br&gt;
&amp;nbsp;&lt;br&gt;
MATLAB will try to look the file named 'filename' and not&lt;br&gt;
'data_??mat'. You need to build the string of path with the&lt;br&gt;
variable filename&lt;br&gt;
&lt;br&gt;
Take a look of:&lt;br&gt;
&amp;gt; help strings&lt;br&gt;
&lt;br&gt;
2. MATLAB cannot load subset of variables in MAT file&lt;br&gt;
For correct calling syntax, take a look &lt;br&gt;
&amp;gt; help load&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jul 2008 20:24:01 -0400</pubDate>
      <title>Re: problem with a 'for' loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172073#441331</link>
      <author>Francesco </author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.fr&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g4o31t$bj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Francesco &quot; &amp;lt;fsarnari@maths.leeds.ac.uk&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;g4nse3$gco$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi everybody,&lt;br&gt;
&amp;gt; &amp;gt; I am trying, in a for loop over the index j to &lt;br&gt;
load .mat &lt;br&gt;
&amp;gt; &amp;gt; files (data_%d.mat) from an external hard drive E:\.&lt;br&gt;
&amp;gt; &amp;gt; My files are stored in the directory dir2 and I would &lt;br&gt;
like &lt;br&gt;
&amp;gt; &amp;gt; to load only variables var1 and var2 from the .mat file.&lt;br&gt;
&amp;gt; &amp;gt; I am trying to use this string, but it doesn't work...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for j=1:N&lt;br&gt;
&amp;gt; &amp;gt;     filename = num2str(j,'data_%d.mat');&lt;br&gt;
&amp;gt; &amp;gt;     load(j,'E:\dir1\dir2\filename', 'var1','var2')&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; What am I doing wrong? Could you help me to write it &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1. 'E:\dir1\dir2\filename'&lt;br&gt;
&amp;gt;  &lt;br&gt;
&amp;gt; MATLAB will try to look the file named 'filename' and not&lt;br&gt;
&amp;gt; 'data_??mat'. You need to build the string of path with &lt;br&gt;
the&lt;br&gt;
&amp;gt; variable filename&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Take a look of:&lt;br&gt;
&amp;gt; &amp;gt; help strings&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2. MATLAB cannot load subset of variables in MAT file&lt;br&gt;
&amp;gt; For correct calling syntax, take a look &lt;br&gt;
&amp;gt; &amp;gt; help load&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
Thanks, Bruno!&lt;br&gt;
Now it works.&lt;br&gt;
Francesco</description>
    </item>
  </channel>
</rss>

