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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Documentation for overloading builtin end() class method..?

Asked by Brad Stiritz on 18 Jun 2013

Hi everyone,

I need to find official documentation / examples for overloading the builtin classdef 'end' method. I have an example in my code base which I got from somewhere a couple of years ago, but unfortunately I didn't document where I got the code from! Here's a correctly-working method from one of my classdefs:

methods
    function outIndex = end(obj,~,~)
        outIndex = obj.Nvalues;
        assert(outIndex>0,'Invalid use of method end() for empty vector');
    end
end

I'm looking for a URL or two please that documents what those two trailing arguments refer to..? I can't seem to locate anything via Google or the R2013a Help Window.

Thanks, Brad

0 Comments

Brad Stiritz

Products

1 Answer

Answer by Matt J on 18 Jun 2013
Accepted answer

The information you're requesting is in "doc end", available from the command line. To quote,

You can overload the end statement for a user object by defining an end method for the object. The end method should have the calling sequence end(obj,k,n), where obj is the user object, k is the index in the expression where the end syntax is used, and n is the total number of indices in the expression. For example, consider the expression

    A(end-1,:)

The MATLAB software calls the end method defined for A using the syntax

    end(A,1,2)

1 Comment

Brad Stiritz on 18 Jun 2013

Thanks Matt, I appreciate your help.

Matt J

Contact us