Effacer les filtres
Effacer les filtres

Loop through same procedure for different inputs.

2 vues (au cours des 30 derniers jours)
Ben Bawtree
Ben Bawtree le 24 Mar 2022
Commenté : Ben Bawtree le 24 Mar 2022
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

Réponse acceptée

Jan
Jan le 24 Mar 2022
Modifié(e) : Jan le 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by