For loop execution.

2 visualizzazioni (ultimi 30 giorni)
Telema Harry
Telema Harry il 23 Mar 2021
Commentato: Telema Harry il 23 Mar 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

Risposta accettata

William
William il 23 Mar 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 Commento
Telema Harry
Telema Harry il 23 Mar 2021
Problem solved. Thank you so much.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by