0

The min and max functions in MATLAB work on only integer values. How can I find the min and max of a double vector?

a = [2.1 3.4 5.6 7.6]
min(a)

returns to me:

Subscript indices must either be real positive integers or logicals.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
Yuseferi
  • 7,931
  • 11
  • 67
  • 103
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 15:53

2 Answers2

6

You've assigned min as a variable name for an array somewhere in your code.

When you call min(a), MATLAB is trying to grab the indices [2.1,3.4,5.6,7.6] from your array min. To fix this problem, simply call the variable something else.

EDIT: And if you're running it outside of a function, clear min and max, as @Acorbe points out.

Doresoom
  • 7,398
  • 14
  • 47
  • 61
4

You need to clear min and max since they are assigned already and their variable counterparts hide the function names.

To use them as functions, do first

 clear min
 clear max
Acorbe
  • 8,367
  • 5
  • 37
  • 66