octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

histogram and histcounts


From: Lars Winterfeld
Subject: histogram and histcounts
Date: Mon, 16 Nov 2015 16:01:49 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 22.10.2015 15:23, Julien Bect wrote:
> Anyway, note that it is now recommended in Matlab's documentation to
> use the new function "histogram" (introduced in R2014b) instead of
> "hist".
>
> Others will correct me if I'm wrong, but I don't think there is a
> corresponding "histogram" function in Octave yet.
>
> This would be a welcome contribution for sure ;-)


Hi list,

I implemented a first version of histcounts(). It works for 1D-arrays
(todo: categorical arrays and matrix input, and more testing).
Two questions:

(1) Once it is ready, should I post it to this list or upload it as a
"patch" here? https://savannah.gnu.org/patch/?func=additem&group=octave

(2) histcounts() and histogram() share many input parameters, how to
parse them properly without duplicating code?

For example, in my implementation, this already works:
[N, edges, bin] = histcounts(x, nbins, 'Normalization', 'probability')
[N, edges] = histcounts(x, 'BinMethod','fd', 'BinLimits',[2,3])

This should work:
histogram(x, 'BinMethod','scott', 'facecolor','r', 'edgecolor','b');
histogram(ax, x, nbins, 'facecolor','r', 'edgecolor','b');

I think it would be good if histogram() called histcounts() to do the
counting. How to deal with the extra plot options?
The number of input arguments to histcounts() is variable and it
requires some parsing to even find out the supposed meaning of each
argument (is it scalar or a vector, etc.). I think, all options that are
unknown to histcounts() should be passed to the bar() function that
later draws the histogram. I think it is not a good idea to list all
possible plot option names to filter them out.

Btw: The old hist() function first calls the undocumented
__plt_get_axis_arg__ to filter out the optional axis handle in the
beginning. It does not call histc().

I do I had two ideas:

* create a helper function like __histogram_parse_args() function, that
both call. This helper function would be global, is that okay?

* Silently change the interface (okay?) to something like [N, edges,
bin, _extraoptions] = histcounts(vargin), where _extraoptions is a list
of options that histcounts() did not use. Pass them to bar().

Are there any style guidelines for such a case?

Greetings,
Lars


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]