For loop execution.

2 ビュー (過去 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 Center および File ExchangeLoops 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