Clear Filters
Clear Filters

Loop through same procedure for different inputs.

2 views (last 30 days)
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

Accepted Answer

Jan
Jan on 24 Mar 2022
Edited: Jan on 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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!