Borrar filtros
Borrar filtros

Loop through same procedure for different inputs.

2 visualizaciones (últimos 30 días)
Ben Bawtree
Ben Bawtree el 24 de Mzo. de 2022
Comentada: Ben Bawtree el 24 de Mzo. de 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

Respuesta aceptada

Jan
Jan el 24 de Mzo. de 2022
Editada: Jan el 24 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by