Index exceeds matrix dimensions when finding max value

前端 未结 3 1212
不思量自难忘°
不思量自难忘° 2020-12-12 02:40

I have been trying to find the max value from an array. But I keep getting the following error. Please advise.

scores = [19212       56722       73336                


        
相关标签:
3条回答
  • 2020-12-12 03:12

    you probably have a variable called max. Try

    clear max
    max(scores)
    
    0 讨论(0)
  • 2020-12-12 03:30

    Have you defined an array called max ?

    scores = [19212       56722       73336       44805       47268 ]
    
    max(scores)
    
    ans = 73336
    

    If I define an array called max

    max=[1:10]
    
    max(scores)
    
    ??? Index exceeds matrix dimensions.
    

    Check by using the which function

    which max
    
    max is a variable.
    

    It should be

    which max
    
    built-in (C:\Program Files\MATLAB\R2009a\toolbox\matlab\datafun\@logical\max)  % logical method
    
    0 讨论(0)
  • 2020-12-12 03:38

    To get the indices of the maximal value: scores=1:10; find(scores == max(scores))

    If you have two maximum values:

    clear max
    scores=10:-1:1;
    scores=[scores 10];
    find(scores == max(scores))
    
    ans =
    
         1    11
    

    As you might guess max return the max of an array:

    >> max(scores)
    
    ans =
    
        10
    
    0 讨论(0)
提交回复
热议问题