MATLAB Answers

How to plot data only certain days of a year.

4 ビュー (過去 30 日間)
Ro
Ro 2021 年 5 月 6 日
編集済み: Ro 2021 年 5 月 6 日
How to plot or bar data for only certain days of the year. X axis will 365 days Y axis will have cyclist
Eg if the year has 365 days and Jan has cyclist data for day 10, day 12 and day 14 of that month.
Feb has cyclist data for day 1,3,7,8,10,12,14 for that month March has cyclist data for day 12, 15,20,22, 23, 24, 25, 27 for that month.. And so on... How to I get to plot these EXACT days of the month on the x axis without data for other days of the months and year? I want to keep each months data under their assigned month but still show if it’s day 2 or 11 etc I want all this data on 1 graph as I said with y axis being cyclist and x axis being days each month

回答 (1 件)

KSSV
KSSV 2021 年 5 月 6 日
You may proceed something like below:
t = datetime(2020,1,1):datetime(2020,12,31) ;
y = rand(size(t)) ; % random y-axis values for demo
% make required dates to plot
jan_t = datetime(2020,1,[10 12 14]) ;
feb_t = datetime(2020,2,[1,3,7,8,10,12,14]) ;
mar_t = datetime(2020,3,[12, 15,20,22, 23, 24, 25, 27]) ;
ti = [jan_t feb_t mar_t] ;
% plot
[idx,ia] = ismember(t,ti) ;
plot(ti,y(idx))
  1 件のコメント
Ro
Ro 2021 年 5 月 6 日
Hi Using code above and real dates, and corresponding cyclist data I am getting ERROR USING DATATIME/HORZCAT DIMENSIONS OF MATRICES BEING CANCATENATED ARE NOT CONSISTENT
For each one of those dates above has number of cyclist data for each date. So for example Jan 10th has 82 cyclist Jan 12th has 829 cyclist Jan 14th has 176 cyclist. And so on... Same for the extracted dates for feb and each date extracted for March etc....each date had an a #of cyclist. How do you plot the corresponding cyclist for each date of each month. While still maintaining dates and everything on 1 graph.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by