Path: news.mathworks.com!not-for-mail
From: Loren Shure <loren@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Calling a function by looping through a vector
Date: Mon, 28 Sep 2009 08:38:29 -0400
Organization: The MathWorks
Lines: 30
Message-ID: <MPG.252a784da3bbf925989a30@news.mathworks.com>
References: <h9mpb4$b0r$1@fred.mathworks.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1254141509 4189 172.31.57.214 (28 Sep 2009 12:38:29 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 28 Sep 2009 12:38:29 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:573331


In article <h9mpb4$b0r$1@fred.mathworks.com>, leprekhan@yahoo.com 
says...
> Hello everybody,
> I'm trying to call a function that takes a vector and does performs an operation on it.
> I have multiple vectors to send it so I though of sending the vectors in a loop:
> 
> a, b and c are all vectors.
> 
> x = ['a' 'b' 'c'];
> 
> for i = 1 : length(x)
>     PerformOperation(x(i))
> end
> 
> instead of:
> 
> PerformOperation(a)
> PerformOperation(b)
> PerformOperation(c)
> 
> 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.
> 
> Much appreciated.
> 

The function arrayfun might help.

-- 
Loren
http://blogs.mathworks.com/loren