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

New to MATLAB?

Change the function calling name instead of rename the file

Asked by Focu

Focu (view profile)

on 27 Jan 2013

I have a script where I call, several times, a function called FCN in its code. I'm testing different functions for my problem. But for each one I want to test I must rename that file to FCN.m so it is called correctly by the script.

Let's say I want to keep the files named as FCN1.m, FCN2.m, FCN3.m, ..., but in my script (Main.m) I would like that I type somewhere the name of the file with the function I want to test and when i call y = FCN(x,z) it will understand which of the files I`m testing.

Thanks

0 Comments

Focu

Focu (view profile)

Tags

Products

No products are associated with this question.

2 Answers

Answer by Cedric Wannaz

Cedric Wannaz (view profile)

on 27 Jan 2013
Edited by Cedric Wannaz

Cedric Wannaz (view profile)

on 27 Jan 2013
Accepted answer

Anonymous function (look for them in the help, and/or for function handles) at the top of your test script:

 FCN = @(x,z) FCN1(x,z) ;

and then calling FCN() will call FCN1..

1 Comment

Focu

Focu (view profile)

on 27 Jan 2013

Thanks!

Cedric Wannaz

Cedric Wannaz (view profile)

Answer by Image Analyst

Image Analyst (view profile)

on 27 Jan 2013
Edited by Image Analyst

Image Analyst (view profile)

on 27 Jan 2013

Make main.m a function, not a script. Put a function in main.m (or it could be a separate m-file) that simply calls the desired version of FNC, so then you only need to make the change in one place:

function main()
  y= FCN(42, pi);
function y= FCN(x, z)
  y = FCN3(x, z);  % Just need to change this one line in main.m.

0 Comments

Image Analyst

Image Analyst (view profile)

Contact us