필터 지우기
필터 지우기

Loop through same procedure for different inputs.

조회 수: 2 (최근 30일)
Ben Bawtree
Ben Bawtree 2022년 3월 24일
댓글: Ben Bawtree 2022년 3월 24일
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

채택된 답변

Jan
Jan 2022년 3월 24일
편집: Jan 2022년 3월 24일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by