Error: "Array indices must have positive or logical values"

2 次查看(过去 30 天)
close all;
clc;
Tp = .00005;
Bw = 10^8;
P = 1; %Watt
R = 10^3; %m
r = 20*10^9; %sps
t = linspace(0,Tp,(r.*Tp));
Fif = 10^9; %intermediate frequency
g = Bw./Tp; %chirp rate
a = 1; %rectangularPulse((t-.5.*Tp)./Tp);
Xif(t) = a.*cos(2*pi*(Fif-.5*Bw).*t + pi*g*t.^2); %g ="chirp rate"
figure;
plot(t,Xif(t));
That's my code, and I keep getting that error for some reason. I'm not sure how to fix it.

回答(1 个)

Walter Roberson
Walter Roberson 2019-3-30
You are getting confused between formula and expressions.
When you define Xif(t) = something, you are probably thinking in terms of typical notation for defining a formula -- a statement that for some arbitrary t to be determined later, that what is on the right hand side defines how the value of Xif should be computed.
But in MATLAB, things do not work that way. I recently explained in the bottom half of https://www.mathworks.com/matlabcentral/answers/453312-matlab-error-array-indices-must-be-positive-or-logical-values#answer_368153

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by