sum of values in matrix with a loop

조회 수: 2 (최근 30일)
zhi cheng
zhi cheng 2022년 10월 15일
답변: Jan 2022년 10월 15일
given a 52560 x 8 double
where the first 5 columns are [ year month day hour minute ], and next 3 columns are speed of 3 different object
the data is recorced with a gap of 10 minutes
therefore, to get the same time value, I know that its row 1 and row 145 (24hours after row 1)
so, I need to sum all the speed with same time, eg
speed of A at 2022 10 15 11 10 = 3.5
speed of A at 2022 10 16 11 10 = 4.5
....
then the avg speed of A at time 11 10 = (3.5+4.5+...)/n
speed of B at 2022 10 15 11 10 = 100
speed of B at 2022 10 16 11 10 = 200
then the avg speed of B at time 11 10 = (100+200+...)/n
X=zeros(1,3);
for i = 1:length(outDates(:,5))
avgspeeds = zeros(1,3);
for j = 1:3
sum1 = outDates(i,5+j) + outDates(i+144,5+j)% 144 to get the next same time value(24hours after previous value)
end
end

답변 (1개)

Jan
Jan 2022년 10월 15일
outDates = rand(52560, 8); % Arbitrary test data
X = reshape(outDates(:, 6:8), 144, [], 3);
Y = squeeze(sum(X, 2) / size(X, 2)); % Mean over 2nd dimension

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by