For loop execution.

1 Ansicht (letzte 30 Tage)
Telema Harry
Telema Harry am 23 Mär. 2021
Kommentiert: Telema Harry am 23 Mär. 2021
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

Akzeptierte Antwort

William
William am 23 Mär. 2021
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 Kommentar
Telema Harry
Telema Harry am 23 Mär. 2021
Problem solved. Thank you so much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by