フィルターのクリア

Plotting histogram in years like BCE, CE

1 回表示 (過去 30 日間)
Madlab
Madlab 2018 年 9 月 25 日
コメント済み: Danny 2022 年 2 月 10 日
I want to plot a histogram of frequency of eruptions based on the years.
However, the data provided is not so simple. It has year in the form of BCE and CE, along with "unknowns". I want to get rid of the unknowns and count the number of eruptions. However, I cannot read the data as an integer/etc as there are strings in it. "500 CE" and "205 BCE" for example. Is there a way to plot the histogram accounting for such data? I have attached a photo of the data sample in the link.
So far, what I have is
% Locating the index for unknowns
ridunknowns = find(strcmp('Unknown',eruptyear));
% Changing the values of Unknowns to NaN in the vector
eruptyear([ridunknowns]) = {NaN};

採用された回答

Steven Lord
Steven Lord 2018 年 9 月 25 日
Define the format for your date data.
fmt = 'yyyy G';
Convert your data into a datetime array. "Unknown" dates become NaT.
S = {'3300 BCE'; '4040 BCE'; 'Unknown'; '1944 CE'};
DT = datetime(S, 'InputFormat', fmt, 'Format', fmt)
Generate 1000 year wide bins.
startBin = datetime('5000 BCE', 'InputFormat', fmt, 'Format', fmt);
endBin = datetime('2001 CE', 'InputFormat', fmt, 'Format', fmt);
E = startBin:calyears(1000):endBin
Create a histogram using the selected edges.
histogram(DT, E)
If instead you want century-wide bins you can specify that as the BinMethod.
histogram(DT, 'BinMethod', 'century')
  1 件のコメント
Danny
Danny 2022 年 2 月 10 日
Can one use only the positive or negative sign instead of BCE/CE ?

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by