HIST function with negative center and single event.

2 次查看(过去 30 天)
Dear all,
My program runs into issue with 'hist' when certain criteria meet. Following is the code:
tr_min_center = floor(min(spike_times)/bin_size)*bin_size + (.5*bin_size);
tr_max_center = ceil(max(spike_times)/bin_size)*bin_size - (.5*bin_size);
tr_centers = tr_min_center:bin_size:tr_max_center;
[tr_n, tr_xout] = hist(spike_times, tr_centers);
When there is only one event in spike_time with a negative number (relate to a synchronization time point), so there is only one negative center, function 'hist' give out error like: Attempted to access xx(0); index must be a positive integer or logical.
I track it down in 'hist' at code line 67 to 75:
if length(x) == 1
if miny == maxy,
miny = miny - floor(x/2) - 0.5;
maxy = maxy + ceil(x/2) - 0.5;
end
binwidth = (maxy - miny) ./ x;
xx = miny + binwidth*(0:x); -- This is the line error occurred since x is a negative number.
Could someone help provide a fix. Thank you!

采纳的回答

Jan
Jan 2011-5-5
As the documentation of HIST explains, "HIST(Y, M)" uses M bins, if M is a scalar. Using a negative or not integer number of bins must fail.
Check the number of bins before calling HIST: For a single bin the calculations are very cheap.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by