Nothing shows up on plot?

1 ビュー (過去 30 日間)
Christina Allen
Christina Allen 2021 年 4 月 19 日
回答済み: VBBV 2022 年 1 月 25 日
MM = 24;
days = 1;
while MM > 0
MM = MM - randi(5);
MM = MM - 7;
days = days + 1;
end
days
plot(days,MM)
%I'm trying to plot the values of MM on the y axis for days 1-4 on the x axis but nothing shows up on the plot.
  1 件のコメント
Christina Allen
Christina Allen 2021 年 4 月 19 日
how can i sequence the data? i set days up in the while loop to be iterated so I figured that would end up making it a sequence.

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

回答 (2 件)

Jonas
Jonas 2021 年 4 月 19 日
your plot contains only one data point because days is 1 x 1 and MM is 1 x1. If you are interested the sequence of data you also have to store the sequence of data
  2 件のコメント
Jonas
Jonas 2021 年 4 月 19 日
just add something during the while like dailyValues(days)=MM . i'm not sure which value you want to save per day

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


VBBV
VBBV 2022 年 1 月 25 日
MM = 24;
days = 1;i =1;% set value to counter
while MM > 0
m(i) = MM;
MM = MM - randi(5);
MM = MM - 7;
d(i) = days;
days = days + 1;
i=i+1;
end
plot(d,m)
Check with this. Hope this helps

Community Treasure Hunt

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

Start Hunting!

Translated by