Display all while loop outputs into a chart?
Ältere Kommentare anzeigen
So I have a bank account of 6000 dollars and it has a 12% annual interest rate. I have to stop the while loop when the 6000 doubles. Just having some trouble displaying this as a chart with one column counting years and the other displaying the balance after each year. This is what I have right now but it only displays the final year and final balance. Please help!
Balance = 6000;
Year = 0;
while (Balance < 12000)
Year = Year + 1;
Balance = Balance*1.12;
end
T = table(Year, Balance)
Antworten (1)
Star Strider
am 4 Mär. 2018
You need to subscript them and save them as vectors:
Balance = 6000;
Year = 0;
k = 1;
while (Balance < 12000)
k = k+1;
Year(k) = Year(k-1) + 1;
Balance(k) = Balance(k-1)*1.12;
end
T = table(Year(:), Balance(:))
figure(1)
plot(Year, Balance)
grid on
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!