How do I concatenate my changing output from a while loop?
이전 댓글 표시
I have wrote a code for my home mortgage calculations. The code pretty much runs a simulation on how sooner I would get down with my outstanding principal balance given an additional amount paid each month? I have used a while loop until my principal balance is greater than 0. My counter is the months. So I would like to know how I can plot the counter (months) and the outstanding balance each iteration?
Here is the code:
function out1 = mortgage(outstanding,interestrate,additional)
p = outstanding;
i = interestrate./100;
escrow = 2339.10./12;
payment = 1268.85;
out1=[];
counter=1;
counter1=1;
while p>0
interest = (p.*i)./12;
principal = payment-interest-escrow;
tp = principal+interest+escrow;
if counter1==12
p=p-tp-additional-31.25-1268.85;
counter1=1;
counter=counter+1;
else
p = p-tp-additional-31.25;
counter = counter+1;
counter1=counter1+1;
end
out1=counter;
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!