Adding values from columns 1:i for each column for a new matrix of the same size
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anna B
am 30 Dez. 2019
Bearbeitet: Stijn Haenen
am 30 Dez. 2019
Hi so I have a 442x25 matrix, what I want to do is for example add values of columns 1 and 2 together to create a new column 2, add values of columns 1, 2 and 3 to create a new column 3, add values of columns 1, 2, 3 and 4 to create a new column 4 and so on until column 25 where all the values will be added. If that makes sense to anyone i would really appreciate your help!
Akzeptierte Antwort
Andrei Bobrov
am 30 Dez. 2019
Bearbeitet: Andrei Bobrov
am 30 Dez. 2019
Let A - your array (442 x 25)
out = cumsum(A,2);
0 Kommentare
Weitere Antworten (1)
Stijn Haenen
am 30 Dez. 2019
Bearbeitet: Stijn Haenen
am 30 Dez. 2019
Something like this?
matrix=[1 2 3; 1 2 3; 1 2 3; 1 2 3];
for i=1:size(matrix,2)
matrix_new(:,i)=sum(matrix(:,1:i),2);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating 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!