<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260465</link>
    <title>MATLAB Central Newsreader - [ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???</title>
    <description>Feed for thread: [ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???</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>Thu, 10 Sep 2009 08:38:03 -0400</pubDate>
      <title>[ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260465#679223</link>
      <author>Andr&#233; Brito</author>
      <description>Hi,&lt;br&gt;
basically, what I'm trying to do is to get the output of ind2sub (or of any function, for that matter) to output a vector and assign it to an existing vector. I know I could assign each element of the output to each element of the existing vector. The problem is when the dimensions of the output are not fixed.&lt;br&gt;
&lt;br&gt;
What I want to do is to be able to specify an output without MATLAB overwriting it and checking its dimensions. My idea is for this function to work regardless of the dimensions, such as replacing:&lt;br&gt;
[ab(1) ab(2) ... ab(N)] = function(...)&lt;br&gt;
with&lt;br&gt;
[ab(1:N)] = function(...)&lt;br&gt;
&lt;br&gt;
As an example, could someone just explain me what is the mechanism behind MATLAB that makes, for example, the function ind2sub output the following:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; [a b] = ind2sub([3 3],5)&lt;br&gt;
a = 2&lt;br&gt;
b = 2&lt;br&gt;
&lt;br&gt;
but if&lt;br&gt;
&amp;gt;&amp;gt; ab = [0 0];&lt;br&gt;
&amp;gt;&amp;gt; ab = ind2sub([3 3],5)&lt;br&gt;
ab = 5&lt;br&gt;
&lt;br&gt;
Meaning that it does not detect that the output vector has dimensions different than 1x1.&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
Andre</description>
    </item>
    <item>
      <pubDate>Thu, 10 Sep 2009 09:45:29 -0400</pubDate>
      <title>Re: [ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260465#679236</link>
      <author>Nasser Abbasi</author>
      <description>&lt;br&gt;
&quot;Andre Brito&quot; &amp;lt;andre_brito23@hotmail.com&amp;gt; wrote in message &lt;br&gt;
news:h8adtb$r4u$1@fred.mathworks.com...&lt;br&gt;
&lt;br&gt;
....&lt;br&gt;
&lt;br&gt;
&amp;gt; As an example, could someone just explain me what is the mechanism behind &lt;br&gt;
&amp;gt; MATLAB that makes, for example, the function ind2sub output the following:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; [a b] = ind2sub([3 3],5)&lt;br&gt;
&amp;gt; a = 2&lt;br&gt;
&amp;gt; b = 2&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; but if&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; ab = [0 0];&lt;br&gt;
&lt;br&gt;
Here you declare ab to be a vector of size 2&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; ab = ind2sub([3 3],5)&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; ab = 5&lt;br&gt;
&lt;br&gt;
But here ind2sub overwrite your variable 'ab' which is a vector, with the &lt;br&gt;
outout of ind2sub. And since you prodvided one place for it to write its &lt;br&gt;
ouuput, it returned one of the output parameters and wrote that into 'ab', &lt;br&gt;
which is a scalar. You old vector 'ab' got expunged I am afraid.&lt;br&gt;
&lt;br&gt;
If you wanted ind2sub to write into your vector 'ab', then do&lt;br&gt;
&lt;br&gt;
EDU&amp;gt;&amp;gt; ab(1) = ind2sub([3 3],5)&lt;br&gt;
&lt;br&gt;
ab =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5     0&lt;br&gt;
&lt;br&gt;
hth&lt;br&gt;
&lt;br&gt;
--Nasser&lt;br&gt;
&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Meaning that it does not detect that the output vector has dimensions &lt;br&gt;
&amp;gt; different than 1x1.&lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Andre </description>
    </item>
    <item>
      <pubDate>Thu, 10 Sep 2009 09:52:01 -0400</pubDate>
      <title>Re: [ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260465#679238</link>
      <author>Andr&#233; Brito</author>
      <description>&amp;gt; You old vector 'ab' got expunged I am afraid.&lt;br&gt;
&lt;br&gt;
Thanks, but do you have an idea how to do it without getting expunged?&lt;br&gt;
&lt;br&gt;
Andre</description>
    </item>
    <item>
      <pubDate>Thu, 10 Sep 2009 10:29:05 -0400</pubDate>
      <title>Re: [ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260465#679249</link>
      <author>Bruno Luong</author>
      <description>&quot;Andre Brito&quot; &amp;lt;andre_brito23@hotmail.com&amp;gt; wrote in message &amp;lt;h8ai80$jp2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; You old vector 'ab' got expunged I am afraid.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks, but do you have an idea how to do it without getting expunged?&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Try this:&lt;br&gt;
&lt;br&gt;
abc = cell(size(ab));&lt;br&gt;
[abc{:}] = ind2sub([3 3],2,2);&lt;br&gt;
ab = [abc{:}]&lt;br&gt;
&lt;br&gt;
Sorry but I don't have time right now to give a more proper explanation; but you should look at comma separated list, function calling, nargout.&lt;br&gt;
&lt;br&gt;
You should also try to understand the way ind2sub contract the first input (size) with respect to the number of outputs.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Thu, 10 Sep 2009 12:47:01 -0400</pubDate>
      <title>Re: [ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260465#679293</link>
      <author>Andr&#233; Brito</author>
      <description>&amp;gt; Try this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; abc = cell(size(ab));&lt;br&gt;
&amp;gt; [abc{:}] = ind2sub([3 3],2,2);&lt;br&gt;
&amp;gt; ab = [abc{:}]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Sorry but I don't have time right now to give a more proper explanation; but you should look at comma separated list, function calling, nargout.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You should also try to understand the way ind2sub contract the first input (size) with respect to the number of outputs.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
Thanks a lot!&lt;br&gt;
I do understand the way ind2sub works.&lt;br&gt;
&lt;br&gt;
The tip that you gave is to save the output as a cell instead of a vector!</description>
    </item>
  </channel>
</rss>

