Even with all my effort, I can not get my plot to show a line, why?
1 view (last 30 days)
Show older comments
clc; clear; format compact;
% Intitiating Variables
Obalance = 3000;
YC = 300;
time = i;
% Creating For Loop
for i = 1:1:216
balance = Obalance;
interest = Obalance*0.005;
Nbalance(i) = Obalance + interest + YC;
Obalance = Nbalance(i);
end
fprintf("%.2f", balance);
plot(1:1:216,balance)
xlabel('time');
ylabel('balance');
0 Comments
Answers (1)
Paul
on 5 Nov 2021
At the end of your loop, the variable balance is a single number. Maybe you wanted
balance(i) = Obalance
so that balance is a 1x216 array?
2 Comments
Walter Roberson
on 5 Nov 2021
Or plot Nbalance instead of balance . Depending on whether you want to plot the starting balance for the period, or the ending balance for the period.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!