Loop plotting for individual years

5 ビュー (過去 30 日間)
Cedric
Cedric 2022 年 11 月 8 日
コメント済み: Cedric 2022 年 11 月 8 日
I am trying to plot the average ice concentration on y axis and the date from december 1 st to 30 of march for each year. (10 individual plots for each year ) I donot know how to do, I assume I wil need to use a loop to start from 2011 to 2011. I would want the plots to show the gaps of the missing dates. where on x axis dates from 1st of december to 30 march for each year and y axis the avaiable average ice concentrations for each year period. The code is as below . Any recommendation or help will be appreciated.
T1 = readtable("Ice concentration data.csv")
T1.DateTime
VN = T1.Properties.VariableNames;
lgdstr = cellfun(@(x)strrep(x,'_','\_'), VN(2:end), 'Unif',0)
figure
plot(T1.DateTime, T1{:,2:end})
grid
legend(lgdstr, 'Location','best')
  2 件のコメント
Voss
Voss 2022 年 11 月 8 日
What are the 10 plots for each year?
Cedric
Cedric 2022 年 11 月 8 日
On the x axis the date from december 1st to march 30 abd y axis the average ice concentration for that period. But not all dates in these period are on csv file. I still want it to show december to march on axis, and themissing y values as no markers

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

採用された回答

Davide Masiello
Davide Masiello 2022 年 11 月 8 日
There's no legend in the example below, because I am not sure what you wanted to do with the cellfun function.
Nevertheless, it should help.
T1 = readtable("Ice concentration data.csv");
allyears = unique(year(T1.DateTime));
for yrs = 1:length(allyears)
idx = year(T1.DateTime)==allyears(yrs);
figure(yrs)
plot(T1.DateTime(idx), T1{idx,2:end})
grid on
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 11 月 8 日
g = findgroups(ymd(T1.DateTime));
Now you can splitapply() some plotting code on elements of your table using groupping variable g

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by