help creating a matrix from data in a for loop.

I have
hrs = 24
Iterations/Hr = 60
for k = 1:hrs
for b = 1: iterations/hr
'conditions'
end
end
how do i take the data from the loops and put it into a 60x24 matrix in order to be able to find max, min, and average of each hour.

 채택된 답변

Voss
Voss 2022년 4월 26일

0 개 추천

hrs = 24; % 24 hours
iterations = 60; % 60 iterations per hour
data = zeros(iterations,hrs); % initialize data to be a 60-by-24 matrix of zeros
for k = 1:hrs
for b = 1:iterations
data(b,k) = k*b; % some result based on 'conditions' (or whetever else)
end
end
% min, max, and average, by hour
min_by_hour = min(data);
max_by_hour = max(data);
avg_by_hour = mean(data);
% same thing, but explicitly saying to operate along the first dimension of data
min_by_hour = min(data,[],1);
max_by_hour = max(data,[],1);
avg_by_hour = mean(data,1);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 4월 26일

답변:

2022년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by