Histogram plot by equal time intervals

16 ビュー (過去 30 日間)
Greek McCoy
Greek McCoy 2022 年 4 月 5 日
コメント済み: Voss 2022 年 4 月 5 日
Dear all,
I have with my the attached dataset that I will like to plot in an equal interval time histogram.
Below here is my code:
clc
A = load ('TutorialSampleT.txt');
Time = A (:,1) ;
x = A (:,2 ) ;
y = A (:,3 ) ;
z = A (:,4 ) ;
Amplitude = A (:,5) ;
%define no of bins
noOfBins=min(Time):0.90:max(Time);
%plot histogram
histogram(Time,numel(noOfBins));
timeFormat=noOfBins;
timeFormat=timeFormat/24;
la=datestr(timeFormat,'HH:MM')
xticks(noOfBins);
xticklabels({la});
And the results:
I will be very happy if I can get some assistance with changing the time intervals to something more unifrom (an hour or 2 interval time will be perfect).
Thank you.

採用された回答

Voss
Voss 2022 年 4 月 5 日
clc
A = load ('TutorialSampleT.txt');
Time = A (:,1) ;
x = A (:,2 ) ;
y = A (:,3 ) ;
z = A (:,4 ) ;
Amplitude = A (:,5) ;
% interval in hours:
% interval = 0.9;
% interval = 1;
interval = 2;
%define no of bins
noOfBins=min(Time):interval:max(Time);
%plot histogram
% histogram(Time,numel(noOfBins));
histogram(Time,numel(noOfBins)-1); % number of bins in the histogram is one less than numel(noOfBins), i.e., noOfBins defines the bin edges
timeFormat=noOfBins;
timeFormat=timeFormat/24;
la=datestr(timeFormat,'HH:MM');
xticks(noOfBins);
xticklabels({la});
  2 件のコメント
Greek McCoy
Greek McCoy 2022 年 4 月 5 日
Hello,
Thank you very much for your answer.
It works perfectly well for me.
--
Sincerely,
Greek
Voss
Voss 2022 年 4 月 5 日
You're welcome!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 4 月 5 日
Rather than specifying the number of bins you could specify the bin edges explicitly.
minutesPerDay = minutes(days(1));
T = datetime('today');
dt = T + minutes(randi(minutesPerDay, 1, 1000));
edges = T + hours(0:2:24);
histogram(dt, edges)
xticks(edges)
  1 件のコメント
Greek McCoy
Greek McCoy 2022 年 4 月 5 日
Hello,
Thank you very much for your response.
Your answer is very valuable to me and works well with my code.
I am definitely going to incorporate it in my code.
--
Sincerely,
Greek

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by