Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Walter Roberson
Walter Roberson il 3 Giu 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 Commenti
Faith Huynh
Faith Huynh il 3 Giu 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 il 3 Giu 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

Accedi per commentare.

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by