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

7 次查看(过去 30 天)
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.

采纳的回答

Chunru
Chunru 2021-11-15
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by