octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dispatch function


From: Julien Bect
Subject: Re: Dispatch function
Date: Sat, 14 May 2016 18:50:33 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0

Le 14/05/2016 18:38, pritika malhotra a écrit :
On 14 May 2016 at 21:54, Julien Bect <address@hidden> wrote:
Le 14/05/2016 17:18, pritika malhotra a écrit :
Hello! I was trying to use this given example from documentation and as this 
function is no longer available.
Then what will be the replacement of "dispatch ("sin", "spsin", "sparse 
matrix");"

Through earlier discussion, I have come to know that we can define classes. How 
can we do that?
A simple illustration if possible Or is there some other to do so.

function y = spsin (x)
    printf ("Calling spsin\n");
    fflush(stdout);
    y = spfun ("sin", x);
endfunction

dispatch ("sin", "spsin", "sparse matrix");
y0 = sin(eye(3));
y1 = sin(speye(3));

Here is the relevant section of the manual:
https://www.gnu.org/software/octave/doc/v4.0.0/Creating-a-Class.html#Creating-a-Class

I don't know if you can do it for sparse matrices...
Thanks.
Yes, I went through this manual.
So in order to use the same function I need to create class of the same name.
I just wanted to know if we have any default classes already existing in octave?

Yes, for instance: struct, double, cell...

If you create a directory named @struct and a function @struct/toto.m inside it, then

toto (x)

will call @struct/toto.m if x is a struct.

But sparse matrices (such as speye(3)) are simply of class double, so I don't think you can achieve what you want.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]