Subscript indices must either be real positive integers or logicals, generic solution

前端 未结 3 1370
忘了有多久
忘了有多久 2020-11-21 06:08

The following error occurs quite frequently:

Subscript indices must either be real positive integers or logicals

I have found ma

3条回答
  •  北海茫月
    2020-11-21 06:25

    In Matlab (and most other programming languages) the multiplication sign must always be written. While in your math class you probably learned that you can write write a(a+a) instead of a*(a+a), this is not the same in matlab. The first is an indexing or function call, while the second is a multiplication.

    >> a=0
    
    a =
    
         0
    
    >> a*(a+a)
    
    ans =
    
         0
    
    >> a(a+a)
    Subscript indices must either be real
    positive integers or logicals.
    

提交回复
热议问题