[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #53199] hist returns different results dependi
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument |
Date: |
Wed, 21 Feb 2018 12:04:49 -0500 (EST) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0 |
Update of bug #53199 (project octave):
Status: None => Works For Me
_______________________________________________________
Follow-up Comment #1:
There is a difference between the two calling syntaxes. When you call hist
with a vector you directly set the bin centers. When you call hist with just
the number of bins to use it determines the bin centers based on the range of
the data. The two are not the same. Use the second output argument to see
the calculated bin centers. Try the following code:
a = [ 1, 2, 3, 4, 0;
5, 4, 6, 7, 8;
9, 12, 11, 10, 0;
13, 16, 15, 14, 0;
17, 20, 19, 18, 0;
21, 22, 23, 2, 0;
24, 27, 26, 25, 0;
28, 31, 30, 29, 0;
32, 35, 34, 33, 0;
36, 39, 38, 37, 0;
40, 43, 42, 41, 0;
44, 47, 46, 45, 0;
48, 51, 50, 49, 0;
52, 55, 54, 53, 0];
a = a(:);
b = min (a)
n = max(a)
[cnt1, ctr1] = hist(a, 1:n);
ctr1
[cnt2, ctr2] = hist(a, n);
ctr2
In Octave this produces
octave:19> diary on
octave:20> a = [ 1, 2, 3, 4, 0;
> 5, 4, 6, 7, 8;
> 9, 12, 11, 10, 0;
> 13, 16, 15, 14, 0;
> 17, 20, 19, 18, 0;
> 21, 22, 23, 2, 0;
> 24, 27, 26, 25, 0;
> 28, 31, 30, 29, 0;
> 32, 35, 34, 33, 0;
> 36, 39, 38, 37, 0;
> 40, 43, 42, 41, 0;
> 44, 47, 46, 45, 0;
> 48, 51, 50, 49, 0;
> 52, 55, 54, 53, 0];
octave:21> a = a(:);
octave:22> b = min (a)
b = 0
octave:23> n = max(a)
n = 55
octave:24> [cnt1, ctr1] = hist(a, 1:n);
octave:25> ctr1
ctr1 =
Columns 1 through 19:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19
Columns 20 through 38:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
35 36 37 38
Columns 39 through 55:
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
54 55
octave:26> [cnt2, ctr2] = hist(a, n);
octave:27> ctr2
ctr2 =
Columns 1 through 8:
0.50000 1.50000 2.50000 3.50000 4.50000 5.50000 6.50000
7.50000
Columns 9 through 16:
8.50000 9.50000 10.50000 11.50000 12.50000 13.50000 14.50000
15.50000
Columns 17 through 24:
16.50000 17.50000 18.50000 19.50000 20.50000 21.50000 22.50000
23.50000
Columns 25 through 32:
24.50000 25.50000 26.50000 27.50000 28.50000 29.50000 30.50000
31.50000
Columns 33 through 40:
32.50000 33.50000 34.50000 35.50000 36.50000 37.50000 38.50000
39.50000
Columns 41 through 48:
40.50000 41.50000 42.50000 43.50000 44.50000 45.50000 46.50000
47.50000
Columns 49 through 55:
48.50000 49.50000 50.50000 51.50000 52.50000 53.50000 54.50000
octave:28> diary off
Could you try the same code in Matlab and also report the version of Matlab
you are using? Octave used to be Matlab compatible, but I notice they are now
trying to deprecate the hist() function and move to the histogram function
instead.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?53199>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, jsh, 2018/02/21
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument,
Rik <=
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, jsh, 2018/02/21
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, jsh, 2018/02/21
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, Rik, 2018/02/21
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, jsh, 2018/02/21
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, Rik, 2018/02/22
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, Michael Leitner, 2018/02/22
- [Octave-bug-tracker] [bug #53199] hist returns different results depending on 2nd 1:n/n input argument, Rik, 2018/02/26