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.

 采纳的回答

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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrices and Arrays 的更多信息

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by