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

조회 수: 2 (최근 30일)
noobmaster69
noobmaster69 2019년 3월 30일
댓글: Rena Berman 2019년 10월 28일
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