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:
Retrieve internal function name that is different from file name?

Subject: Retrieve internal function name that is different from file name?

From: Xiaoxiao

Date: 30 Jul, 2009 14:20:14

Message: 1 of 4

Hello,

I am trying to retrieve internal function name that is different from
the .m file name, but failed to do it.

For example, I have a .m file named as test.m, and inside the mysum.m,
I have:

function c = mysum_July302009(a,b)
    c = a+b;

If possible, I would like to obtain the mysum_July302009 inside the
mysum.m and display it. For example,

function c = mysum_July302009(a,b)
    c = a+b;
    thisfun_str = ...... % don't know how to obtain mysum_July302009
here
   disp(thisfun_str)

The reason I want to do this is because I would like to keep the .m
file name the same, and then I can keep them in source control
repository for version control. But I also would like to keep track of
the version inside the program itself by the internal funcation name
which is different from the .m file name, if possible. Otherwise, I
will have to define a version number variable inside the function and
change it to keep track of the version. I think using the internal
function name to indicate the version number will be better, if
possible.

I have tried 'profile on', execute code, 'profile report'; and
'dbstack' inside the mysum.m but didn't work.

Any suggestions will be appreciated (either on version control, or on
retrieve the internal function name that is different from filename).

Subject: Retrieve internal function name that is different from file name?

From: Dave Brackett

Date: 31 Jul, 2009 15:55:19

Message: 2 of 4

Xiaoxiao <xiaoxiaoyang@live.com> wrote in message <f9332649-1cab-4025-981e-909bd35fe50d@24g2000yqm.googlegroups.com>...
> Hello,
>
> I am trying to retrieve internal function name that is different from
> the .m file name, but failed to do it.
>
> For example, I have a .m file named as test.m, and inside the mysum.m,
> I have:
>
> function c = mysum_July302009(a,b)
> c = a+b;
>
> If possible, I would like to obtain the mysum_July302009 inside the
> mysum.m and display it. For example,
>
> function c = mysum_July302009(a,b)
> c = a+b;
> thisfun_str = ...... % don't know how to obtain mysum_July302009
> here
> disp(thisfun_str)
>
> The reason I want to do this is because I would like to keep the .m
> file name the same, and then I can keep them in source control
> repository for version control. But I also would like to keep track of
> the version inside the program itself by the internal funcation name
> which is different from the .m file name, if possible. Otherwise, I
> will have to define a version number variable inside the function and
> change it to keep track of the version. I think using the internal
> function name to indicate the version number will be better, if
> possible.
>
> I have tried 'profile on', execute code, 'profile report'; and
> 'dbstack' inside the mysum.m but didn't work.
>
> Any suggestions will be appreciated (either on version control, or on
> retrieve the internal function name that is different from filename).

What about this?:

function_filename='test_function.m' % the name of the file
fid=fopen(function_filename,'r') % open the file for reading
first_line_of_function=fgetl(fid) % read in the first line of the file

[token, remain]=strtok(first_line_of_function,'=') % splits either side of the equals sign
[token2, remain2]=strtok(remain,'(') % splits either side of the open bracket

actual_function_name=token2(2:end) % removes the equals from what's left to give the name of the function


hope that helps

Subject: Retrieve internal function name that is different from file name?

From: Xiaoxiao

Date: 31 Jul, 2009 16:06:00

Message: 3 of 4

On Jul 31, 11:55 am, "Dave Brackett" <davebrack...@hotmail.com> wrote:
> Xiaoxiao <xiaoxiaoy...@live.com> wrote in message <f9332649-1cab-4025-981e-909bd35fe...@24g2000yqm.googlegroups.com>...
> > Hello,
>
> > I am trying to retrieve internal function name that is different from
> > the .m file name, but failed to do it.
>
> > For example, I have a .m file named as test.m, and inside the mysum.m,
> > I have:
>
> > function c = mysum_July302009(a,b)
> >     c = a+b;
>
> > If possible, I would like to obtain the mysum_July302009 inside the
> > mysum.m and display it. For example,
>
> > function c = mysum_July302009(a,b)
> >     c = a+b;
> >     thisfun_str = ...... % don't know how to obtain mysum_July302009
> > here
> >    disp(thisfun_str)
>
> > The reason I want to do this is because I would like to keep the .m
> > file name the same, and then I can keep them in source control
> > repository for version control. But I also would like to keep track of
> > the version inside the program itself by the internal funcation name
> > which is different from the .m file name, if possible. Otherwise, I
> > will have to define a version number variable inside the function and
> > change it to keep track of the version. I think using the internal
> > function name to indicate the version number will be better, if
> > possible.
>
> > I have tried 'profile on', execute code, 'profile report'; and
> > 'dbstack' inside the mysum.m but didn't work.
>
> > Any suggestions will be appreciated (either on version control, or on
> > retrieve the internal function name that is different from filename).
>
> What about this?:
>
> function_filename='test_function.m' % the name of the file
> fid=fopen(function_filename,'r') % open the file for reading
> first_line_of_function=fgetl(fid) % read in the first line of the file
>
> [token, remain]=strtok(first_line_of_function,'=') % splits either side of the equals sign
> [token2, remain2]=strtok(remain,'(') % splits either side of the open bracket
>
> actual_function_name=token2(2:end) % removes the equals from what's left to give the name of the function
>
> hope that helps- Hide quoted text -
>
> - Show quoted text -

Thank you very much for the help, Dave. This should work.

 I didn't realize we can write something by ourselves (just thought of
Matlab's own functions). Thanks again for the help and have a nice
weekend!

Subject: Retrieve internal function name that is different from file name?

From: pm

Date: 31 Jul, 2009 19:44:57

Message: 4 of 4

On Jul 30, 7:20 am, Xiaoxiao <xiaoxiaoy...@live.com> wrote:
> Hello,
>
> I am trying to retrieve internal function name that is different from
> the .m file name, but failed to do it.
>
> For example, I have a .m file named as test.m, and inside the mysum.m,
> I have:
>
> function c = mysum_July302009(a,b)
>     c = a+b;
>
> If possible, I would like to obtain the mysum_July302009 inside the
> mysum.m and display it. For example,
>
> function c = mysum_July302009(a,b)
>     c = a+b;
>     thisfun_str = ...... % don't know how to obtain mysum_July302009
> here
>    disp(thisfun_str)
>
> The reason I want to do this is because I would like to keep the .m
> file name the same, and then I can keep them in source control
> repository for version control. But I also would like to keep track of
> the version inside the program itself by the internal funcation name
> which is different from the .m file name, if possible. Otherwise, I
> will have to define a version number variable inside the function and
> change it to keep track of the version. I think using the internal
> function name to indicate the version number will be better, if
> possible.
>
> I have tried 'profile on', execute code, 'profile report'; and
> 'dbstack' inside the mysum.m but didn't work.
>
> Any suggestions will be appreciated (either on version control, or on
> retrieve the internal function name that is different from filename).

First point: What is wrong with just opening your function like:

function c = mysum(a,b)
version = 'July302009';

No point in hiding this information in the declaration name of the
function, which matlab ignores, then having to jump through hoops to
bring it back.

Second point: What source control system are you using? If for example
you are using SVN, you can write

function c = mysum(a,b)
version = '$LastChangedDate$'

and enable keywords for that file (I'm not going into details because
I don't know what system you're using) and SVN will fill in the value
for you as soon as you commit. The purpose of having a source code
control system is that you shouldn't need to fill out this stuff
manually.

-pm

Tags for this Thread

No tags are associated with 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