필터 지우기
필터 지우기

Creating an array of sums of another array.

조회 수: 2 (최근 30일)
Daniel Ring
Daniel Ring 2018년 12월 26일
답변: TADA 2018년 12월 26일
I have an array of 322,872 data points. I want to create another array of the sum of the numbers in the first array in segments of 730 data points (sum from 1 to 730 would be the first point in the new array, sum from 731 to 1,460 would be the second point in the new array and so on). The code I have right now (which is not working) is the following:
i = 1;
j = 730;
while j < 322871;
i = i + 730;
j = j + 730;
k = 1;
x = zeros(442,1);
while k < 441;
x(k,:) = sum(WS_50mCopy(i:j,:));
end
end

채택된 답변

TADA
TADA 2018년 12월 26일
n = 18; %n = 322872 in your case
windowSize = 5;% n = 730 in your case
% generate vector of size n
x = round(rand(1,n) * 100)
lastWindowSize = mod(n, windowSize);
% reshape x to a matrix of the wanted window size
x1 = reshape([x zeros(1, windowSize - lastWindowSize)], windowSize, (n + windowSize - lastWindowSize)/windowSize)
% sum each column of the matrix to generate the sums vector
y = sum(x1, 1)
These are the vectors that were generated:
x =
60 47 70 70 64 3 7 32 53 65 41 82 72 97 53 33 11 61
x1 =
60 3 41 33
47 7 82 11
70 32 72 61
70 53 97 0
64 65 53 0
y =
311 160 345 105

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by