how to sum different rows within a column
古いコメントを表示
I have 2 columns with 3101 values and i want to add the row 1&2 then row 2&3, 3&4 and so on..
I want to execute this calculation for the entire column with a cummulative sum
p=0.5*(column1(row1+row2))*column2(row2-row1)
the next row should be = 0.5*(column1(row2+row3))*column2(row3-row2) + p
How can I select 2 row values in the same column with the output created in a different column?
Thanks in advance
採用された回答
その他の回答 (1 件)
Image Analyst
2022 年 3 月 31 日
"to add the row 1&2 then row 2&3, 3&4 and so on.." you can use conv:
kernel = [1;1];
sums = conv(column1, kernel, 'valid');
kernel = [-1; 1];
diffs = conv(column2, kernel, 'valid');
If you want it multiplied by 0.5 and cumulatively summed, you can .....
Well actually I think Star's for loop approach is much simpler to do and understand than my vectorized approach so just go with that.
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!