Why do I get "Array indices must be positive integers or logical values" error when using "angle" function?

Why do I get "Array indices must be positive integers or logical values" error when using "angle" function?
>> z = 22+i
>> a = angle(z)
>> z =
22.0000 + 1.0000i
ERROR: Array indices must be positive integers or logical values.

 Réponse acceptée

Based on the error message, it seems like you have a variable with the name "angle" stored in your workspace that overshadows the "angle" function

4 commentaires

us=3;
us is a scalar value
f=-100:0.1:100;
X=0.8*(1+exp(-j*0.16*pi*f)).*(us(f+50)-us(f-50))+0.5*(exp(-j*0.04*pi*f))+exp(-j*0.12*pi*f).*(us(f+25)-us(f-25))+4.5*(exp(-j*0.08*pi*f)).*(us(f+10)-us(f-10));
The us(f+50) part asks to index the variable us . The index value is f+50 but f starts at -100 so f+50 starts with -50 . You are asking to index the scalar us at location -50 .
Reminder: MATLAB has absolutely no implied multiplication.
When I look at the expression, it looks to me as if us is intended to be the Unit Step function, rather than a scalar variable.
num2str of an integer does not have a '.' in it. Eventually you remove all of the characters, at which point size is 0 and end then becomes 0 so a(end) becomes a(0)
That code assumes that the values in Scores and Scores2 are all positive integers, and will give you an error if that is not the case.
That code also assumes that the Scores and Scores2 values are all either 1 or 2, but will not give an error if they are larger integers instead.
@Nguyen Quoc Khanh: t is not a nonzero integer. It can't be used for an index on the LHS of that assignment. You don't need to anyway.
s = cos(2*pi*100*t) + 2*cos(2*pi*200*t+pi/2) + 3*cos(2*pi*200*t+pi/4); % quá trình lấy mẫu

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Produits

Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by