<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260426</link>
    <title>MATLAB Central Newsreader - Function output dimensions</title>
    <description>Feed for thread: Function output dimensions</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>Wed, 09 Sep 2009 21:05:23 -0400</pubDate>
      <title>Function output dimensions</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260426#679149</link>
      <author>Andr&#233; Brito</author>
      <description>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;
(Maybe it has been answered before how it can be done, or that this is not the correct way to do it, or I'm missing something really obvious but I couldn't find a similar problem with the search terms I've used)&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;
Andr</description>
    </item>
    <item>
      <pubDate>Wed, 09 Sep 2009 21:33:07 -0400</pubDate>
      <title>Re: Function output dimensions</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260426#679151</link>
      <author>jrenfree</author>
      <description>On Sep 9, 2:05&#160;pm, &quot;Andre Brito&quot; &amp;lt;andre_brit...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;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;
&amp;gt;&lt;br&gt;
&amp;gt; (Maybe it has been answered before how it can be done, or that this is not the correct way to do it, or I'm missing something really obvious but I couldn't find a similar problem with the search terms I've used)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;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;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; [a b] = ind2sub([3 3],5)&lt;br&gt;
&amp;gt;&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&amp;gt;&amp;gt; ab = [0 0];&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; ab = ind2sub([3 3],5)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ab = 5&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Meaning that it does not detect that the output vector has dimensions different than 1x1.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Andr&lt;br&gt;
&lt;br&gt;
you would have to do:&lt;br&gt;
&lt;br&gt;
[ab(1) ab(2)] = ind2sub([3 3],5);&lt;br&gt;
&lt;br&gt;
By specifying only one output for ind2sub, such as when you type:&lt;br&gt;
&lt;br&gt;
ab = ind2sub([3 3],5);&lt;br&gt;
&lt;br&gt;
it doesn't care that ab used to be a 2x1 vector.  It will override&lt;br&gt;
that and make it a 1x1 vector, since you're telling ind2sub to only&lt;br&gt;
return one variable.</description>
    </item>
    <item>
      <pubDate>Wed, 09 Sep 2009 21:56:04 -0400</pubDate>
      <title>Re: Function output dimensions</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260426#679154</link>
      <author>Andr&#233; Brito</author>
      <description>&amp;gt; you would have to do:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [ab(1) ab(2)] = ind2sub([3 3],5);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; By specifying only one output for ind2sub, such as when you type:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ab = ind2sub([3 3],5);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; it doesn't care that ab used to be a 2x1 vector.  It will override&lt;br&gt;
&amp;gt; that and make it a 1x1 vector, since you're telling ind2sub to only&lt;br&gt;
&amp;gt; return one variable.&lt;br&gt;
&lt;br&gt;
Thanks!&lt;br&gt;
&lt;br&gt;
I just realized I don't have a question in my original post!!!&lt;br&gt;
&lt;br&gt;
I realize I can do what you suggest but 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;
Cheers, Andr</description>
    </item>
  </channel>
</rss>

