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

조회 수: 8 (최근 30일)
Suresh R
Suresh R 2021년 11월 15일
답변: Chunru 2021년 11월 15일
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