Azzera filtri
Azzera filtri

Loop through same procedure for different inputs.

2 visualizzazioni (ultimi 30 giorni)
Hi! I am getting stuck on something i believe is quite trivial, i have written out the code in full below that i am using. I am trying to combine the long code into a singular loop that filters through the three different time periods (5s,10s, 20s) giving the three seperate results as an output. Any help is greatly appreciated!
cnt = 15; % centre point (s)
fqn = 200; % scale factor (Hz)
t = 5; % time period (s)
LBD = fqn.*(cnt-(t./2)); % define lower boundary
UBD = fqn.*(cnt+(t./2)); % define upper boundary
c5_5s = c5(LBD:UBD,3); % isolate values within the boundary conditions
UM5S = mean(c5_5s); % calculate time-avg mean
disp(['t_5s = ',num2str(UM5S), ' m/s']) % display result
t = 10; % time period (s)
LBD = fqn.*(cnt-(t./2)); % define lower boundary
UBD = fqn.*(cnt+(t./2)); % define upper boundary
c5_10s = c5(LBD:UBD,3); % isolate values within the boundary conditions
UM10S = mean(c5_10s); % calculate time-avg mean
disp(['t_10s = ',num2str(UM10S), ' m/s']) % display result
t = 20; % time period (s)
LBD = fqn.*(cnt-(t./2)); % define lower boundary
UBD = fqn.*(cnt+(t./2)); % define upper boundary
c5_20s = c5(LBD:UBD,3); % isolate values within the boundary conditions
UM20S = mean(c5_20s); % calculate time-avg mean
disp(['t_20s = ',num2str(UM20S), ' m/s']) % display result

Risposta accettata

Jan
Jan il 24 Mar 2022
Modificato: Jan il 24 Mar 2022
cnt = 15; % centre point (s)
fqn = 200; % scale factor (Hz)
for t = [5, 10, 20] % time period (s)
LBD = fqn.*(cnt-(t./2)); % define lower boundary
UBD = fqn.*(cnt+(t./2)); % define upper boundary
ct = c5(LBD:UBD,3); % isolate values within the boundary conditions
UMtS = mean(ct); % calculate time-avg mean
fprintf('t_%is = %f m/s', t, UMtS); % display result
end

Più risposte (0)

Categorie

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

Tag

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by