Calculate value based on previous row plus adjacent row
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154982/image.png)
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.
0 Kommentare
Antworten (3)
Azzi Abdelmalek
am 19 Jul. 2016
Bearbeitet: Azzi Abdelmalek
am 19 Jul. 2016
idx=1:6
out=B(idx)+A(idx+1)
0 Kommentare
Thorsten
am 19 Jul. 2016
A = [0:5];
B = [0 1 3 6 10 15];
ind = 3:6;
C(ind) = A(ind) + B(ind-1)
M = [A' B' C']
0 Kommentare
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!