フィルターのクリア

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.
  1 件のコメント
Yonghe
Yonghe 2011 年 5 月 6 日
Thank you! Your suggestion works.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by