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

Contact us at files@mathworks.com