For loop execution.

조회 수: 1 (최근 30일)
Telema Harry
Telema Harry 2021년 3월 23일
댓글: Telema Harry 2021년 3월 23일
I am trying to compute the code shown below. but keep getting error. I will be happy if someone could please look at the code
clear all;
N = 200;
Fs = 50;
Fo1 = 10;
Fo2 = 60;
ts = 1/Fs;
T = (N - 1)* ts;
A1 = 2;
A2 = 4;
t = 0:ts:T;
B = [0.1:0.1:0.9, 1:0.5:10];
X = zeros (length(B),N);
for m = 1: length(B)
if (B(m) >= 0.1 & B(m) < 1)
for d = 1: N
X(m,d) = A1*sin(2*pi.*(Fo1./B(m)).* t(d)).*( t >= 0.1 & t <= 2.5) + ...
A2* cos(2*pi.*(Fo2./B(m)).* t(d)).*(t>=2.6 & t <4.9);
end
elseif (B(m) >= 1)
for d = 1: N
Sn(m,d) = A1*sin(2*pi.*(Fo1./B(m)).* t(d)).*( t >= 0.1 & t <= 2.5) + ...
A2* cos(2*pi.*(Fo2./B(m)).* t(d)).*(t>=2.6 & t <4.9);
end
end
end

채택된 답변

William
William 2021년 3월 23일
I think it may be the 4 clauses that read like (t >= 0.1 & t <= 2.5). Shouldn't these say (t(d) >= 0.1 & t(d) <= 2.5)?
  댓글 수: 1
Telema Harry
Telema Harry 2021년 3월 23일
Problem solved. Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by