Srishti M
Srishti M

Reputation: 543

Logical error in applying logarithm

In implementing a formula I get the error error (Attempted to access sum(0.0508041); index must be a positive integer or logical.)

Upvotes: 1

Views: 89

Answers (1)

chappjc
chappjc

Reputation: 30579

The reason for the error (Attempted to access sum(0.0508041); index must be a positive integer or logical.) is because you are using sum as a variable. NEVER use the name of a built-in MATLAB function as a variable name. Instead of summing values, this line attempts to index the variable named sum with non-integer values in lnR.

Also, from one i to the next, you overwrite all previous values in lnR, having never used them. This also means that when you finally use lnR after the loop, it is just the lnR from the last loop iteration. AND, you should always pre-allocate arrays (e.g. lnR = zeros(l2,1);). Similarly, pre-allocate x, y, and z in lorenzo.m.

Upvotes: 2

Related Questions