Why do I get a "not enough arguments" error when initializing a data set within a stack?
8 views (last 30 days)
Show older comments
When initializing a stack I wish to set up a data set with initial values of zeros as a vector array of size n - TBD in a separate script. See the attached code. The code returns an error at this line saying "Error using Stack (line 44) Not enough input arguments." . I have tried to declare n as a property but that does not fix the problem. Does anyone have any suggestions?
Any advice about this would be appreciated.
3 Comments
Geoff Hayes
on 26 Sep 2014
@Alexander - please also include the line of code that you are using to instantiate the Stack object. Are you saying that the following line, as executed in the Command Window,
myStack = Stack(42)
throws the error? Or are you instantiating it as
myStack = Stack
and not passing an input argument for the stack size...which would explain the Not enough input arguments error.
Answers (1)
Geoff Hayes
on 27 Sep 2014
The code for the constructor (from above)
% Constructor
function [self] = Stack (n)
% Initialize the stack
self.data = zeros([1,n]);
self.top = 0; % empty
self.depth = n;
is identical (with the exception of the class name) to the code for the RPMCalculator class found at MATLAB answer 156307.
It is easy to reproduce the problem. If no input argument is passed when creating an instance of this class
myStack = RPMCalculator;
then the following error is raised
Error using RPMCalculator (line 14)
Not enough input arguments.
which is identical to the message observed by Alexander. As the constructor requires the stack size (through the input parameter n) then that is what must be passed in
stackSize = 43;
myStack = RPMCalculator(stackSize);
The above should work for Alexander's class: just substitute Stack for RPMCalculator.
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!