Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
change the name of a function in a loop

Subject: change the name of a function in a loop

From: Jose

Date: 20 Jul, 2010 16:39:04

Message: 1 of 4

Hello guys, i have this piece of code:

depth=[1 2 3 4]
panelx=[2 3 5 6]
k=length(panelx)

load data.mat


        for I=1:k
        e=panelx(I)
        epsn(e)=depth(I)
        xdata=datax(:,I);
        sendvar2m(e)=proc1serial(e,xdata,epsn)
        end


I would like to subs proc1serial for the the fuction procIserial, where the variable I can change with the loop.

Any help?

Thanks.

Subject: change the name of a function in a loop

From: Sean

Date: 20 Jul, 2010 16:54:04

Message: 2 of 4

"Jose " <jose.l.vega@gmail.com> wrote in message <i24jf8$adm$1@fred.mathworks.com>...
> Hello guys, i have this piece of code:
>
> depth=[1 2 3 4]
> panelx=[2 3 5 6]
> k=length(panelx)
>
> load data.mat
>
>
> for I=1:k
> e=panelx(I)
> epsn(e)=depth(I)
> xdata=datax(:,I);
> sendvar2m(e)=proc1serial(e,xdata,epsn)
> end
>
>
> I would like to subs proc1serial for the the fuction procIserial, where the variable I can change with the loop.
>
> Any help?
>
> Thanks.

Use anonymous functions:
my_fun =@(e,xtata,epsn)proc1serial(e,xdata,epsn)
then when you need to change it redefine myfun:
my_fun =@(e,xtata,epsn)procIserial(e,xdata,epsn)

sendvar2m(e)= my_fun(e,xdata,epsn);

Subject: change the name of a function in a loop

From: someone

Date: 20 Jul, 2010 16:59:04

Message: 3 of 4

"Jose " <jose.l.vega@gmail.com> wrote in message <i24jf8$adm$1@fred.mathworks.com>...
> Hello guys, i have this piece of code:
>
> depth=[1 2 3 4]
> panelx=[2 3 5 6]
> k=length(panelx)
>
> load data.mat
>
>
> for I=1:k
> e=panelx(I)
> epsn(e)=depth(I)
> xdata=datax(:,I);
> sendvar2m(e)=proc1serial(e,xdata,epsn)
> end
>
>
> I would like to subs proc1serial for the the fuction procIserial, where the variable I can change with the loop.
>
> Any help?
>
> Thanks.

See the answer to Q4.6 of the MATLAB FAQ at:

http://matlabwiki.mathworks.com/MATLAB_FAQ

You should be able to adapt the solution to meet your needs.

Subject: change the name of a function in a loop

From: Steven_Lord

Date: 20 Jul, 2010 17:07:47

Message: 4 of 4



"Jose " <jose.l.vega@gmail.com> wrote in message
news:i24jf8$adm$1@fred.mathworks.com...
> Hello guys, i have this piece of code:
>
> depth=[1 2 3 4]
> panelx=[2 3 5 6]
> k=length(panelx)
>
> load data.mat
>
>
> for I=1:k
> e=panelx(I)
> epsn(e)=depth(I)
> xdata=datax(:,I); sendvar2m(e)=proc1serial(e,xdata,epsn)
> end
>
>
> I would like to subs proc1serial for the the fuction procIserial, where
> the variable I can change with the loop.
>
> Any help?

Construct the string containing the name of the function and convert it into
a function handle using STR2FUNC, then invoke the function using the
function handle.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us