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:
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.
Subject: Calling a function by looping through a vector
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
--
Subject: Calling a function by looping through a vector
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.
>
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.