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

1 次查看(过去 30 天)
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.

回答(1 个)

Walter Roberson
Walter Roberson 2016-6-3
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 个评论
Faith Huynh
Faith Huynh 2016-6-3
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by