How to save outputs from previous iterations and plot

my code is:
a = 20000;
R = 0.06;
n = 180;
r = R/12;
z = amortization(a,R,n);
for i = 1:180
b = a*r;
%b is interest payed in first month
c = z-b;
%c is amount applied towards loan principle
a = a-c;
%a is new amount left to be paid
array2table(a)
end
I want to be able to save all the a values from previous iterations and plot them against i(1:180). As of right now my code is overwriting my a value and only producing one output instead of saving all values of a. Please help I am new to Matlab.

 채택된 답변

KSSV
KSSV 2022년 8월 19일
편집: KSSV 2022년 8월 19일
n = 180 ;
a = zeros(1,n) ;
a(1) = 20000;
R = 0.06;
r = R/12;
z = amortization(a(1),R,n);
for i = 2:n
b = a(i-1)*r;
% b is interest payed in first month
c = z-b;
% c is amount applied towards loan principle
a(i) = a(i-1)-c;
%a is new amount left to be paid
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

질문:

2022년 8월 19일

댓글:

2022년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by