필터 지우기
필터 지우기

Calculate value based on previous row plus adjacent row

조회 수: 5 (최근 30일)
chels19
chels19 2016년 7월 19일
답변: Thorsten 2016년 7월 19일
Hi,
I have a matrix of two columns and need to calculate the values of the second column based on the previous row of column 2 plus the adjacent row of column 1. For example,
Given the above matrix, cell B4 has been calculated by getting the value of cell B3 + A4. This carries on for the duration of the matrix.
I can do this quite easily in Excel but am finding it rather difficult in Matlab.
Any help/suggestions would be greatly appreciated please.

답변 (3개)

Adam
Adam 2016년 7월 19일
For that particular example:
B = cumsum( A )';

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 19일
편집: Azzi Abdelmalek 2016년 7월 19일
idx=1:6
out=B(idx)+A(idx+1)

Thorsten
Thorsten 2016년 7월 19일
A = [0:5];
B = [0 1 3 6 10 15];
ind = 3:6;
C(ind) = A(ind) + B(ind-1)
M = [A' B' C']

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by