Trailing Sum Calculation using pre-defined kernel starting at incorrect cell
古いコメントを表示
Table Z:

Goal: Calculating a 12-point trailing sum for any date point looking upward in the table, e.g. 20-May-2016 must display the sum of the shaded area (0.1768).
So far:
[rows, columns] = size(Z);
onesVector = ones(rows, 1);
kernel12t = [0;0;0;1;1;1;1;1;1;1;1;1;1;1;1]; % Kernel that computes
% the trailing 12 values
trailingSum12t = zeros(rows, columns);
for col = 4 : columns
thisColumn = Z{:, col}; % Extract all rows from this column.
cellSum12t = conv(onesVector, kernel12t, 'same');
valuesSum12t = conv(thisColumn, kernel12t, 'same');
trailingSum12t(:, col) = valuesSum12t;
end
The outcome of "trailingSum12t" is displayed below. However, the highlighted cell shouldn't be 0.1760 but 0.1768. Strangely I find the correct sum of the 12-point trailing kernel (0.1768) in a cell (row 8) where it shouldn't be.

Another issue is found in "cellSum12t" (see below): rows 551-554 should contain 12's!

The upper part of "cellSum12t" looks perfect though (see below):

採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Statistics and Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!