Plotting help with a simple problem

9 Ansichten (letzte 30 Tage)
DiamondsRain
DiamondsRain am 18 Feb. 2021
Kommentiert: Star Strider am 19 Feb. 2021
I've been trying to fiqure out how to make this line visable within this plot, and can't seem to get or understand exactly what to do. I was hoping someone could explain how I would make the lines on this simple data set visiable.
clear, clc
a=750000; %staring amount
b=35000; %starting withdrawl
y=0; %years
while a>b
a=a-b;
a=a*1.045; %interest
b=b*1.015; %inflation rate
y=y+1; %year/time step
disp(y)
yyaxis left
plot(y,a)
yyaxis right
plot(y,b)
end

Akzeptierte Antwort

Star Strider
Star Strider am 19 Feb. 2021
Subscript all of them.
Try this:
a=750000; %staring amount
b=35000; %starting withdrawl
y=0; %years
while a>b
a=a-b;
a=a*1.045; %interest
b=b*1.015; %inflation rate
y=y+1; %year/time step
av(y) = a;
bv(y) = b;
yv(y) = y;
end
figure
yyaxis left
plot(yv,av)
yyaxis right
plot(yv,bv)
Since ‘y’ increments by 1 and is always an integer, it is convenient to use it as a counter and subscript.
  2 Kommentare
DiamondsRain
DiamondsRain am 19 Feb. 2021
Thanks, I had been trying with a seperate counter and had some troubles, but this helped a lot thank you!
Star Strider
Star Strider am 19 Feb. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by