user3595632
user3595632

Reputation: 5730

What is "index should be positive integer(not complex format integer)" in MATLAB?

// I made function like this:
function y = ZL(L,f)
if isvector(f)
    y=1j*2*pi.*f*L;
else
    y=1j*2*pi.*f*L;
end

// and command : L = 10, f= -10000:100:10000, ZL=ZL(L,f);

// then error : 
index should be positive integer(not complex format integer) or boolean
-> this error is translated by me who is Korean; sorry

what's wrong with it?

Upvotes: 0

Views: 57

Answers (1)

Bentoy13
Bentoy13

Reputation: 4966

First time you call ZL = ZL(L,f), you don't get any error.

If you try to call your command a second time, you'll get this error: Index exceeds matrix dimensions. It's because you affect the variable ZL, so the second time it's not the function you're calling but you"re trying to get elements from the array ZL.

So please don't use same name for a variable and an existing function, otherwise the function name is masked by the variable.

Upvotes: 3

Related Questions