Even with all my effort, I can not get my plot to show a line, why?

1 view (last 30 days)
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');

Answers (1)

Paul
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
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.
Jagger Garcia
Jagger Garcia on 5 Nov 2021
I troubleshot that myself and you were right, just had to stare at it some more I guess. Thank you for the help.

Sign in to comment.

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!