oop - Matlab Class Method: Too many arguments -


i found related questions, didn't find answer in there.

i'm writing simple little matlab class in order learn oop syntax in matlab. i'm familiar python, , pulling hair out trying work matlab. here's definition:

classdef car < handle       properties         speed = [0,0]   %x,y velocity         position = [0,0]         running = false      end      methods         function obj = car(pos, spd)             obj.position = pos;             obj.speed = spd;         end          function accelerate(obj,x,y)    % add speed             obj.speed = obj.speed + [x,y]         end          function position = getposition(obj)             position = obj.position         end          function start(obj)             obj.running = true         end          function stop(obj)             obj.running = false         end     end  end 

this not done, i'm using little script mess object:

foo = car([1,1],[0,2]) foo.start foo.accelerate(2,3) 

instantiation works, method call throws error. foo.start, example:

error using car/start many input arguments. 

what missing??

since can't figure out how delete question, i'll best answer it. other languages, object oriented programing in matlab wants see obj first parameter in class methods (like self in python). reference object necessary modify attributes. not including in method definitions, when called method getting "too many arguments" error. that's because if foo.method(a,b), object foo passed parameter, function getting 3 inputs, i.e. method(foo,a,b).

i went through code , added obj in appropriate places, failed use clear command in matlab command window. since i'm new matlab, unaware of importance. assumed saving file , re-instantiating class sufficient. not.

i hope helps comes across question.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -