Thread Subject: Writing Matlab functions for Java classes

Subject: Writing Matlab functions for Java classes

From: Stanislav Funiak

Date: 7 Jul, 2008 10:45:03

Message: 1 of 2

Hi,

Suppose that I have a Java class, foo. Is there a way to
write a Matlab function that will be only invoked for
objects of type foo (or for its descendants)? For example, I
would like to write a function "sum" s.t. if x is of type foo,

sum(x)

will invoke my function and not the built-in one. With
Matlab classes (pre-7.6), I can put the Matlab function to
the @foo directory. Is there something similar for Java
classes?

Many thanks,
Stano

Subject: Writing Matlab functions for Java classes

From: Matt

Date: 30 Oct, 2008 18:31:49

Message: 2 of 2

You could write a sum method for your java class. As long as the return type for the method was something that Matlab is happy with (double, int, boolean, a instance of the foo class, etc) then you can call the method with
>> out = sum(foo);
or the more traditional
>> out = foo.sum;

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code Stanislav Funiak 7 Jul, 2008 06:45:06
function Stanislav Funiak 7 Jul, 2008 06:45:06
java Stanislav Funiak 7 Jul, 2008 06:45:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

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.

Contact us at files@mathworks.com