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!
Best Answer