필터 지우기
필터 지우기

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 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