Why do I get a "not enough arguments" error when initializing a data set within a stack?

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

Alexander - it sounds like you are instantiating an instance of a Stack class where the constructor is expecting a certain number of inputs and your code (to create the instance) is not supplying enough inputs. What is the line of code that you are executing, and what is the function signature for the constructor?
Geoff,
The line that the error points to is line 44 which reads: &nbsp self.data = zeros([1,n]);
Here is the method function:
% Constructor
function [self] = Stack (n)
% Initialize the stack
self.data = zeros([1,n]); % <---- I keep getting the error here
self.top = 0; % empty
self.depth = n;
(I changed the name of the file and the classdef to Stack but that does not seem to make a difference)
@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.

Sign in to comment.

Answers (1)

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.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Asked:

on 26 Sep 2014

Edited:

on 27 Sep 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!