フィルターのクリア

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?
Walter Roberson
Walter Roberson 2016 年 6 月 3 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by