How can i plot (annual plots) data according to the years (which are listed in the first column)?

2 ビュー (過去 30 日間)
Yasmin Samy
Yasmin Samy 2017 年 9 月 28 日
コメント済み: KL 2017 年 9 月 30 日
Hello, I have a table where the first column shows the years. I would like to plot the values for each year. example:
year month value 2007 3 1 2007 4 5 2007 5 3 2008 4 3 2008 5 2
so for the above i would want 2 graphs..one for 2007 and one for 2008. The number of values for each year isn`t constant. What is the fastest why to do this? thanks

回答 (2 件)

KL
KL 2017 年 9 月 28 日
編集済み: KL 2017 年 9 月 28 日
plot(your_table{your_table.year==2007,{'value'}})
something like that should work, I have't tested it. Let me know if it worked.
  2 件のコメント
Yasmin Samy
Yasmin Samy 2017 年 9 月 28 日
Thanks. It`s similar to what you wrote, only maybe i need to loop it so it automatically plots all the years. I still haven`t found the solution.
KL
KL 2017 年 9 月 29 日
years = [2007, 2008]; %and so on
for k = 1:length(years)
figure(k)
plot(your_table{your_table.year==years(k),{'value'}});
%your legend, title, etc
end

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


Yasmin Samy
Yasmin Samy 2017 年 9 月 29 日
For those who would like to know the answer...i did a conditional loop. There was some problems with the last lines for each year which i had to consider. so i did two loops inside the first one also! If someone has an easier or faster way, feel free to share!
thanks
  1 件のコメント
KL
KL 2017 年 9 月 30 日
Two loops do sound redundant. If you could share a better dataset, it's easier to give you a better solution.

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by