Filter löschen
Filter löschen

how to calculate row values based on the previous row value of a column?

4 Ansichten (letzte 30 Tage)
input array
a= [1,2,3,4,5,6,7,8,9,10]
the output array is as follows. where 100 is initial value we are calculating for 1. for 2 we are taking output of 1.
b= (1*100)+100 = 200
b = (2*200)+ 200 = 600
b=(3*600)+600 = 2400
like wise i need to calculate for all elements of a.

Akzeptierte Antwort

Chunru
Chunru am 15 Nov. 2021
a= [1,2,3,4,5,6,7,8,9,10];
b = 100; % initial value
for i=1:numel(a)
b= (a(i)*b)+b;
fprintf("i=%2d b=%d\n", i, b)
end
i= 1 b=200 i= 2 b=600 i= 3 b=2400 i= 4 b=12000 i= 5 b=72000 i= 6 b=504000 i= 7 b=4032000 i= 8 b=36288000 i= 9 b=362880000 i=10 b=3991680000

Weitere Antworten (0)

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!

Translated by