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 ExchangeCreating 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