function - What does this MATLAB class to and why isn't it working on my PC? -


the first 1 in documentation: http://www.mathworks.com/help/matlab/matlab_oop/getting-familiar-with-classes.html

the class is:

classdef basicclass    properties       value    end    methods       function r = roundoff(obj)          r = round([obj.value],2);       end       function r = multiplyby(obj,n)          r = [obj.value] * n;       end    end end 

when run way

a = basicclass a.value = pi/3; 

it works fine , should piece of code

a = basicclass(pi/3); 

gives following error:

"error using round

too many input arguments."

what mean? (i'm using r2014a) stupid use oop in matlab? lol

your error message doesn't correct compared code, whichever missing class constructor (as mentioned @ half way down link):

classdef basicclass   properties     value   end   methods      % class constructor -> can pass pi/3 into.     function obj = basicclass ( varargin )       if nargin == 1         obj.value = varargin{1};       end     end      % methods     function r = roundoff(obj)       r = round([obj.value],2);     end     function r = multiplyby(obj,n)       r = [obj.value] * n;     end   end end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -