Clear Filters
Clear Filters

Getting the error 'Subscript indices must either be real positive integers or logicals' when using the mode() function

1 view (last 30 days)
I have a column vector (20000 x 1) which is a 20 thousand entries long of numbers which are all decimals with 9 decimal places. I'm trying to find the mode of the column. This vector is called amps. I'm trying to find the mode of the column, but when I type in:
M = mode(amps);
It returns an error saying 'Subscript indices must either be real positive integers or logicals. '
Mean, median, var, and sum all work, but mode doesn't. What am I doing wrong?
I can't post code for legal reasons.

Answers (1)

Walter Roberson
Walter Roberson on 3 Jun 2016
In MATLAB, when you create a variable with the same name as one of the MATLAB routines, you are unable to directly call the MATLAB routine by the same name until the variable is no longer in scope.
To put this more directly: you named a variable "mode", and you will need to rename that variable or else you will not be able to call the routine named "mode".
  2 Comments
Faith Huynh
Faith Huynh on 3 Jun 2016
I don't have a variable named "mode." I have a vector named "amps," and I was trying to make another variable, 'M,'equal to the mode of "amps."
Or am I misunderstanding you?
Walter Roberson
Walter Roberson on 3 Jun 2016
At the command line, give the command
dbstop if error
and then run your code. When it stops, please show the output of
which mode
whos mode

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!