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:
How to resolve conflict function call in Matlab?

Subject: How to resolve conflict function call in Matlab?

From: Michael Teo

Date: 14 Sep, 2010 07:22:07

Message: 1 of 6

To all matlab experts,

How to resolve conflict function call in Matlab?

For example, in Java, there are 2 classes 'Date'. To resolve ambiguity in Java, we can specify clearly the class name to use / call by java.util.Date or java.sql.Date.

How can we handle this in Matlab? Let assume we will like to call Matlab's builtin function 'xlswrite' and custom-built function of the same name 'xlswrite' within the same .m program, how do we specify (in syntax) so that Matlab know which functions to reference to?

Thanks in advance for the helps!

Subject: How to resolve conflict function call in Matlab?

From: Bruno Luong

Date: 14 Sep, 2010 07:38:04

Message: 2 of 6

"Michael Teo" <mteo@empiricap.com> wrote in message <i6n7qv$i9e$1@fred.mathworks.com>...
> To all matlab experts,
>
> How to resolve conflict function call in Matlab?
>
> For example, in Java, there are 2 classes 'Date'. To resolve ambiguity in Java, we can specify clearly the class name to use / call by java.util.Date or java.sql.Date.
>
> How can we handle this in Matlab? Let assume we will like to call Matlab's builtin function 'xlswrite' and custom-built function of the same name 'xlswrite' within the same .m program, how do we specify (in syntax) so that Matlab know which functions to reference to?
>
> Thanks in advance for the helps!

There is no such thing in Matlab. You could use addpath() and rmpath() to select/hide the file in the specific path for ulterior call, but there is no way to do it on the fly (except fro script).

A better structure is to use OOP to define a method specific to the class.

Bruno

Subject: How to resolve conflict function call in Matlab?

From: James Tursa

Date: 14 Sep, 2010 07:44:08

Message: 3 of 6

"Michael Teo" <mteo@empiricap.com> wrote in message <i6n7qv$i9e$1@fred.mathworks.com>...
> To all matlab experts,
>
> How to resolve conflict function call in Matlab?
>
> For example, in Java, there are 2 classes 'Date'. To resolve ambiguity in Java, we can specify clearly the class name to use / call by java.util.Date or java.sql.Date.
>
> How can we handle this in Matlab? Let assume we will like to call Matlab's builtin function 'xlswrite' and custom-built function of the same name 'xlswrite' within the same .m program, how do we specify (in syntax) so that Matlab know which functions to reference to?
>
> Thanks in advance for the helps!

doc builtin

Put your custom function on the MATLAB path. When you call xlswrite it will call your custom function. When you want to call the builtin function, use builtin.

James Tursa

Subject: How to resolve conflict function call in Matlab?

From: Michael Teo

Date: 14 Sep, 2010 08:13:10

Message: 4 of 6

> There is no such thing in Matlab. You could use addpath() and rmpath() to select/hide the file in the specific path for ulterior call, but there is no way to do it on the fly (except fro script).
>
> A better structure is to use OOP to define a method specific to the class.
>
> Bruno

> Put your custom function on the MATLAB path. When you call xlswrite it will call your custom function. When you want to call the builtin function, use builtin.
>
> James Tursa

Thanks Bruno, James.

I guess the 'better' approach will be using OOP because 'builtin' can only differentiate between Matlab and a custom function. There will be an issue if there are 2 custom functions of the same name.

Matlab OOP is pretty new, there are limitation examples. Which books / sites will you recommend for Matlab OOP? Thanks.

Subject: How to resolve conflict function call in Matlab?

From: Doug Schwarz

Date: 14 Sep, 2010 11:02:21

Message: 5 of 6

In article <i6n947$bhn$1@fred.mathworks.com>,
 "James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote:

> "Michael Teo" <mteo@empiricap.com> wrote in message
> <i6n7qv$i9e$1@fred.mathworks.com>...
> > To all matlab experts,
> >
> > How to resolve conflict function call in Matlab?
> >
> > For example, in Java, there are 2 classes 'Date'. To resolve ambiguity in
> > Java, we can specify clearly the class name to use / call by java.util.Date
> > or java.sql.Date.
> >
> > How can we handle this in Matlab? Let assume we will like to call Matlab's
> > builtin function 'xlswrite' and custom-built function of the same name
> > 'xlswrite' within the same .m program, how do we specify (in syntax) so
> > that Matlab know which functions to reference to?
> >
> > Thanks in advance for the helps!
>
> doc builtin
>
> Put your custom function on the MATLAB path. When you call xlswrite it will
> call your custom function. When you want to call the builtin function, use
> builtin.
>
> James Tursa

This won't work because xlswrite is not a built-in functions, it's an
m-file.

As an alternative to building a whole class just for this, the OP could
just put his xlswrite in a package directory, e.g.,

  .../+package/xlswrite.m

and then call it with

  package.xlswrite(arguments)

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: How to resolve conflict function call in Matlab?

From: James Tursa

Date: 14 Sep, 2010 15:30:29

Message: 6 of 6

Doug Schwarz <see@sig.for.address.edu> wrote in message <see-F0FA73.07022114092010@news.frontiernet.net>...
> In article <i6n947$bhn$1@fred.mathworks.com>,
> "James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote:
>
> >
> > doc builtin
> >
> > Put your custom function on the MATLAB path. When you call xlswrite it will
> > call your custom function. When you want to call the builtin function, use
> > builtin.
> >
> > James Tursa
>
> This won't work because xlswrite is not a built-in functions, it's an
> m-file.

Hmmm ... you're right. I don't use builtin much and had assumed there wasn't a distinction between toolbox m-file functions and other MATLAB functions, but that isn't true. There isn't any mention of this in the doc for builtin. But I guess that means that the toolbox directories aren't treated as anything special with regards to the builtin function. Good to know. Thanks.

James Tursa

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