I created a class with the name Player. This is the code of the class
classdef Player
properties
Name
Score
end
methods
end
end
Now I use the following code to create an instance of the class. In the final line I attempt to print the value of properties
Player evergreen = new Player();
evergreen.Name = "Roger Federer" ;
evergreen
An error is thrown up while I run the script. This is the error - Error using Player Too many input arguments.
Error in Team (line 1) Player evergreen = new Player();
Team is the name of the file containing script.
Compared to Java, things in Matlab work a little bit differently. When working with classes, you don't need to specify the type when declaring variables and constructors must be called without the
newkeyword. While your code run perfectly under Java, in order to make it work under Matlab you have to rewrite it as follows:For a brief introduction to object oriented programming in Matlab, read this.