필터 지우기
필터 지우기

HIST function with negative center and single event.

조회 수: 2 (최근 30일)
Yonghe
Yonghe 2011년 5월 5일
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