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.

 Respuesta aceptada

Voss
Voss el 26 de Abr. de 2022
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);

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 26 de Abr. de 2022

Respondida:

el 26 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by