<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261733</link>
    <title>MATLAB Central Newsreader - Calling a function by looping through a vector</title>
    <description>Feed for thread: Calling a function by looping through a vector</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>Sun, 27 Sep 2009 04:23:00 -0400</pubDate>
      <title>Calling a function by looping through a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261733#682899</link>
      <author>Kirk Hammett</author>
      <description>Hello everybody,&lt;br&gt;
I'm trying to call a function that takes a vector and does performs an operation on it.&lt;br&gt;
I have multiple vectors to send it so I though of sending the vectors in a loop:&lt;br&gt;
&lt;br&gt;
a, b and c are all vectors.&lt;br&gt;
&lt;br&gt;
x = ['a' 'b' 'c'];&lt;br&gt;
&lt;br&gt;
for i = 1 : length(x)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PerformOperation(x(i))&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
instead of:&lt;br&gt;
&lt;br&gt;
PerformOperation(a)&lt;br&gt;
PerformOperation(b)&lt;br&gt;
PerformOperation(c)&lt;br&gt;
&lt;br&gt;
Could somebody tell me how to call my function by looping through a vector? The second solution seems like a hack and I'm trying to learn the best possible way to do this.&lt;br&gt;
&lt;br&gt;
Much appreciated.</description>
    </item>
    <item>
      <pubDate>Sun, 27 Sep 2009 04:32:50 -0400</pubDate>
      <title>Re: Calling a function by looping through a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261733#682900</link>
      <author>dpb</author>
      <description>Kirk Hammett wrote:&lt;br&gt;
&amp;gt; Hello everybody,&lt;br&gt;
&amp;gt; I'm trying to call a function that takes a vector and does performs an operation on it.&lt;br&gt;
&amp;gt; I have multiple vectors to send it so I though of sending the vectors in a loop:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a, b and c are all vectors.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = ['a' 'b' 'c'];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i = 1 : length(x)&lt;br&gt;
&amp;gt;     PerformOperation(x(i))&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; instead of:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; PerformOperation(a)&lt;br&gt;
&amp;gt; PerformOperation(b)&lt;br&gt;
&amp;gt; PerformOperation(c)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Could somebody tell me how to call my function by looping through&lt;br&gt;
&amp;gt; a vector? The second solution seems like a hack and I'm trying to&lt;br&gt;
&amp;gt; learn the best possible way to do this.&lt;br&gt;
&lt;br&gt;
x = {a b c};&lt;br&gt;
for i = 1: length(x)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;yourfunc(x{i});&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
    <item>
      <pubDate>Sun, 27 Sep 2009 04:58:03 -0400</pubDate>
      <title>Re: Calling a function by looping through a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261733#682901</link>
      <author>Kirk Hammett</author>
      <description>Thank you for your help!</description>
    </item>
    <item>
      <pubDate>Mon, 28 Sep 2009 12:38:29 -0400</pubDate>
      <title>Re: Calling a function by looping through a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261733#683074</link>
      <author>Loren Shure</author>
      <description>In article &amp;lt;h9mpb4$b0r$1@fred.mathworks.com&amp;gt;, leprekhan@yahoo.com &lt;br&gt;
says...&lt;br&gt;
&amp;gt; Hello everybody,&lt;br&gt;
&amp;gt; I'm trying to call a function that takes a vector and does performs an operation on it.&lt;br&gt;
&amp;gt; I have multiple vectors to send it so I though of sending the vectors in a loop:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a, b and c are all vectors.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = ['a' 'b' 'c'];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i = 1 : length(x)&lt;br&gt;
&amp;gt;     PerformOperation(x(i))&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; instead of:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; PerformOperation(a)&lt;br&gt;
&amp;gt; PerformOperation(b)&lt;br&gt;
&amp;gt; PerformOperation(c)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Could somebody tell me how to call my function by looping through a vector? The second solution seems like a hack and I'm trying to learn the best possible way to do this.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Much appreciated.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
The function arrayfun might help.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Loren&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren&quot;&gt;http://blogs.mathworks.com/loren&lt;/a&gt;</description>
    </item>
  </channel>
</rss>

