<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/160965</link>
    <title>MATLAB Central Newsreader - matlab code doesnt work</title>
    <description>Feed for thread: matlab code doesnt work</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The 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>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 18 Dec 2007 22:00:09 -0500</pubDate>
      <title>Re: matlab code doesnt work</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/160965#406655</link>
      <author>Jos </author>
      <description>kaancho &amp;lt;kaancho12@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;10642267.1198014032538.JavaMail.jakarta@nitrogen.mathforum.&lt;br&gt;
org&amp;gt;...&lt;br&gt;
&amp;gt; thanks for all the replies. The code indeed works. For &lt;br&gt;
some reason when i had to close matlab and restart it to &lt;br&gt;
take the data properly...maybe like Roger said I need to &lt;br&gt;
initialize the array.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
You should not need to close matlab. Issueing a "clear ret" &lt;br&gt;
or even better (!) pre-allocate ret to it's final size &lt;br&gt;
(i.e., initializing) should do.&lt;br&gt;
&lt;br&gt;
The error you get is similar to&lt;br&gt;
&lt;br&gt;
a = ones(3,2) ;&lt;br&gt;
a(1,:) = 1:10 ;&lt;br&gt;
&lt;br&gt;
Jos&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 18 Dec 2007 21:40:02 -0500</pubDate>
      <title>Re: matlab code doesnt work</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/160965#406654</link>
      <author>kaancho</author>
      <description>thanks for all the replies. The code indeed works. For some reason when i had to close matlab and restart it to take the data properly...maybe like Roger said I need to initialize the array.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 16 Dec 2007 06:38:49 -0500</pubDate>
      <title>Re: matlab code doesnt work</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/160965#406356</link>
      <author>Roger Stafford</author>
      <description>kaancho12 &amp;lt;kaancho12@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;11132067.1197780702950.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I am trying to implement this code (which was on a lecture slide that I &lt;br&gt;
found on the internet) but I could not figure out the error code. Any help is &lt;br&gt;
appreciated:&lt;br&gt;
&amp;gt; price = [74.9	108.34	82.52	47.2    10  8;&lt;br&gt;
&amp;gt; 78.85	108.9	82.7	47.34   11  6;&lt;br&gt;
&amp;gt; 79.86	118	83.3	49.44   12  9;&lt;br&gt;
&amp;gt; 88.53	120.05	81.75	48.23   11  9;&lt;br&gt;
&amp;gt; 88.84	134.31	81.13	49.25   12  8&lt;br&gt;
&amp;gt; ];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [n,col] = size(price);&lt;br&gt;
&amp;gt; for i=2:n&lt;br&gt;
&amp;gt; ret(i,:) = (price(i,:)-price(i-1,:))./price(i-1,:);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The error I get is:&lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; run&lt;br&gt;
&amp;gt; Subscripted assignment dimension mismatch.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any idea how to modify my subscript to make this work?&lt;br&gt;
-------&lt;br&gt;
&amp;nbsp;&amp;nbsp;In all likelihood, you are running this, having already created a 'ret' array of &lt;br&gt;
a different size from the above 5 by 6, and matlab complains about the &lt;br&gt;
mismatch in size that it sees.  &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;In any case you should always preallocate to the proper size such arrays that &lt;br&gt;
are to be filled up step-by-step in a for-loop so that their memory can be set &lt;br&gt;
aside ahead of time rather than being expanded in a series of steps.  That will &lt;br&gt;
improve execution time.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 16 Dec 2007 05:32:19 -0500</pubDate>
      <title>Re: matlab code doesnt work</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/160965#406354</link>
      <author>John O'Flaherty</author>
      <description>On Sat, 15 Dec 2007 23:50:41 EST, kaancho12 &amp;lt;kaancho12@hotmail.com&amp;gt;&lt;br&gt;
wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;Hi,&lt;br&gt;
&amp;gt;I am trying to implement this code (which was on a lecture slide that I found on the internet) but I could not figure out the error code. Any help is appreciated:&lt;br&gt;
&amp;gt;price = [74.9	108.34	82.52	47.2    10  8;&lt;br&gt;
&amp;gt;78.85	108.9	82.7	47.34   11  6;&lt;br&gt;
&amp;gt;79.86	118	83.3	49.44   12  9;&lt;br&gt;
&amp;gt;88.53	120.05	81.75	48.23   11  9;&lt;br&gt;
&amp;gt;88.84	134.31	81.13	49.25   12  8&lt;br&gt;
&amp;gt;];&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;[n,col] = size(price);&lt;br&gt;
&amp;gt;for i=2:n&lt;br&gt;
&amp;gt;ret(i,:) = (price(i,:)-price(i-1,:))./price(i-1,:);&lt;br&gt;
&amp;gt;end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;The error I get is:&lt;br&gt;
&amp;gt;??? Error using ==&amp;gt; run&lt;br&gt;
&amp;gt;Subscripted assignment dimension mismatch.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;Any idea how to modify my subscript to make this work?&lt;br&gt;
&lt;br&gt;
It seems to work here- this is the result:&lt;br&gt;
ret = 0         0         0         0         0         0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0527    0.0052    0.0022    0.0030    0.1000   -0.2500&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0128    0.0836    0.0073    0.0444    0.0909    0.5000&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.1086    0.0174   -0.0186   -0.0245   -0.0833         0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0035    0.1188   -0.0076    0.0211    0.0909   -0.1111&lt;br&gt;
&lt;br&gt;
Maybe there's a difference between what you pasted in the message and&lt;br&gt;
what you're running.&lt;br&gt;
-- &lt;br&gt;
John&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 16 Dec 2007 04:50:41 -0500</pubDate>
      <title>matlab code doesnt work</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/160965#406353</link>
      <author>kaancho12</author>
      <description>Hi,&lt;br&gt;
I am trying to implement this code (which was on a lecture slide that I found on the internet) but I could not figure out the error code. Any help is appreciated:&lt;br&gt;
price = [74.9	108.34	82.52	47.2    10  8;&lt;br&gt;
78.85	108.9	82.7	47.34   11  6;&lt;br&gt;
79.86	118	83.3	49.44   12  9;&lt;br&gt;
88.53	120.05	81.75	48.23   11  9;&lt;br&gt;
88.84	134.31	81.13	49.25   12  8&lt;br&gt;
];&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
[n,col] = size(price);&lt;br&gt;
for i=2:n&lt;br&gt;
ret(i,:) = (price(i,:)-price(i-1,:))./price(i-1,:);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
The error I get is:&lt;br&gt;
??? Error using ==&amp;gt; run&lt;br&gt;
Subscripted assignment dimension mismatch.&lt;br&gt;
&lt;br&gt;
Any idea how to modify my subscript to make this work?&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
