Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!not-for-mail
From: dpb <none@non.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Calling a function by looping through a vector
Date: Sat, 26 Sep 2009 23:32:50 -0500
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <h9mq69$vrr$1@news.eternal-september.org>
References: <h9mpb4$b0r$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.eternal-september.org U2FsdGVkX19kEvID8gac7CxMG3SMLI+2geIGtEMzf8TXZx+uAfaA0x1amTVfcSJFpTFneLT/yekvCZ0iTuYR3SFmB/4nsm27Ax9vWTS22KEZfc/SkZEgiCVu+/BQsHkLWFDkj5NxfGXnOdEbP7m6TQ==
X-Complaints-To: abuse@eternal-september.org
NNTP-Posting-Date: Sun, 27 Sep 2009 04:37:30 +0000 (UTC)
In-Reply-To: <h9mpb4$b0r$1@fred.mathworks.com>
X-Auth-Sender: U2FsdGVkX1+E8oUszGkvGpBWKSA+LfyJjNZI3EPg8WA=
Cancel-Lock: sha1:lutSBBCDQLm+xu4D3Wbx0mt2yGE=
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
Xref: news.mathworks.com comp.soft-sys.matlab:573157


Kirk Hammett wrote:
> 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.

x = {a b c};
for i = 1: length(x)
   yourfunc(x{i});
end

--