Basic histogram with histogram function.

I am trying to create a histogram from a data set in excel by importing it to matlab.
I can't get the histogram function to work with a table or data array after import.
I need to use the data set to make a histogram with a bin width of 50 and then subtract one entry per bin.
how do I reference the array or table in the histogram function? how would I subtract one entry per bin?
any help would be greatly appreciated.

3 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 5 月 14 日
Can you share a sample dataset? The correct solution depends on how your data is arranged.
daniel caltrider
daniel caltrider 2020 年 5 月 15 日
I was able to figure out the histogram part by importing the intire .xlsx file with
[num,~,~]=xlsread('histogram2.xlsx');
d=num;
histogram(d,50)
histfit(d,50)
here is a small portion of the full data set:
1756
1055
4193
1156
7285
1095
845
3088
daniel caltrider
daniel caltrider 2020 年 5 月 15 日
I still need help removing one entry per bin.

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

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 15 日
編集済み: Ameer Hamza 2020 年 5 月 15 日

0 投票

To decrease, one entry per bin, try this
[num,~,~]=xlsread('histogram2.xlsx');
d=num;
h = histogram(d,50);
h.BinCounts = h.BinCounts-1

9 件のコメント

daniel caltrider
daniel caltrider 2020 年 5 月 15 日
編集済み: daniel caltrider 2020 年 5 月 15 日
That did not work but lead me in a new direction. I got an error "unable to resolve the name h.BinCounts."
daniel caltrider
daniel caltrider 2020 年 5 月 15 日
Still unable to find a method to do what I want via code. Probably going to remove point from my original data and redo the histogram with the adjusted data set.
Ameer Hamza
Ameer Hamza 2020 年 5 月 15 日
Which MATLAB release are you using? Can you paste your lines of code here?
daniel caltrider
daniel caltrider 2020 年 5 月 15 日
[num,~,~]=xlsread('histogram2.xlsx');
d=num;
histogram(d,50)
I am using R2020a.
This is all the code I have for the histogram I need.
Ameer Hamza
Ameer Hamza 2020 年 5 月 15 日
No, I meant to attach the code which gives error about BinCounts. Can you change your code according to my answer, run it and then paste the code and error message?
daniel caltrider
daniel caltrider 2020 年 5 月 15 日
>> [num,~,~]=xlsread('histogram2.xlsx');
d=num;
h = histogram(d,50);
h.BinCounts = h.BinCounts-1
Error using matlab.graphics.chart.primitive.Histogram/set.BinCounts
Expected input to be nonnegative.
Here you go. Sorry for the misunderstanding.
Ameer Hamza
Ameer Hamza 2020 年 5 月 15 日
Ok. The error is caused because if the height of the histogram for some bins is zero, then subtracting 1 will make it negative (which does not make any sense). Therefore try the following line. It leaves the bins with zero height
h.BinCounts(h.BinCounts>0) = h.BinCounts(h.BinCounts>0)-1
daniel caltrider
daniel caltrider 2020 年 5 月 15 日
It worked! thank you!
Ameer Hamza
Ameer Hamza 2020 年 5 月 15 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by