Why does my plot not display?

I have this function:
function savings
salary=input('Positive number')
while salary<0
soldata=input('Positive number, please')
end
daily_spending=input('Negative number')
while daily_spending>0
daily_spending=input('Negative number, please')
end
savings=salary;
days=1;|
day_counter=1;
months=1;
while months<=12
savings=savings+daily_spending;
if days==30;
months=months+1;
savings=savings+salary;
days=0;
end
day_counter=day_counter+1;
days=days+1;
plot(day_counter, savings);
pause(0.05)
end
The problem I have is that when matlab starts plotting, it shows up the figure but not the line. Why is that? I can't figure it out. Could someone help me? This is what it looks like:
PD: Axes refresh well

1 件のコメント

GMW
GMW 2017 年 5 月 8 日
編集済み: GMW 2017 年 5 月 8 日
You are missing a 'hold'
Try: hold on, plot(day_counter, savings, '.')

サインインしてコメントする。

回答 (2 件)

David Young
David Young 2015 年 1 月 15 日

0 投票

The problem is that both day_counter and savings are scalars, so there is nothing to plot. I suspect that what you need is to store successive values in an array, and plot the array.
Adam
Adam 2015 年 1 月 15 日

0 投票

Both day_counter and savings are scalars so it just plots a single point.

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

2015 年 1 月 15 日

編集済み:

GMW
2017 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by