How to create a structure array for spike data
古いコメントを表示
Hi all
I am using the chronux package to generate some Intespike Interval histograms (ISIs) from neuon spiking data:
http://chronux.org/chronuxFiles/Documentation/chronux/spectral_analysis/pointtimes/isi.html#_top
The program requires that my spike times are given as a structure array but it seems I am not generating a "toy" structure array of spike trains succesfully.
I have the toy example attached (only the section commented as "APC" is my toy code, the rest is the chronux package attached here) which doesn't seem to work.
What is the error here and how can I feed the program with some structure arrays of spiking data as it requires?
thank you in advance.
function[N,B,E] = isi(data,T,err,Nbins,plt)
% Calculate the inter-spike-interval histogram
% Usage: [N,B,E] = isi(data,T,err,Nbins,plt)
%
% Input:
% Note that all times have to be consistent.
%
% data - structure array of spike times (required)
% T - time interval of interest (default all)
% err - 0 for no error bars, 1 for jackknife errors
%
% Nbins - number of bins in the isi
%
% Output:
%
% N - count in bins
% B - bin centres
% E - errorbar (this is 2 sig deviation
% calculated using a jackknife over trials)
% [filename directory_name] = uigetfile('spikeraster_temp.dat', 'home/alexandrapierri/Desktop');
% fullname = fullfile(directory_name, filename);
% spikes_1 = load(fullname);
% data = spikes_1(:,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%APC toy code, generate structure array of spiking data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
field = 'first_neuron';
value = {'pyramidal cell';
[1, 2, 3, 4, 4.5, 4.8, 5, 5.6, 5.8, 6, 6.2, 6.4, 6.9, 7, 9, 10]};
s = struct(field,value);
data=s.first_neuron;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%APC toy code, generate structure array of spiking data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin < 1; error('I need data!'); end
data=padNaN(data); % create a zero padded data matrix from input structural array
data=data'; % transposes data to get it in a form compatible with Murray's routine
if nargin < 2; T = [min(data(:,1)) max(max(data))]; end
if nargin < 3; err = 0;end
if nargin < 4; Nbins = -1; end
if nargin < 5; plt = 'r'; end
if isempty(T); T = [min(min(data)) max(max(data))]; end
if isempty(err); err = 0;end
if isempty(Nbins); Nbins = -1; end
if isempty(plt); plt = 'r'; end
% get the number of intervals in each trial and the indices of spike times
% that are kept
NT = length(data(1,:)); % number of trials
NI=zeros(1,NT);
index(1:NT)=struct('keep',[]);
for n=1:NT
indx = find(data(:,n) >= T(1) & data(:,n) <= T(2) ...
& ~isnan(data(:,n)));
if isempty(indx)
NI(n) = 0;
else
NI(n) = length(indx)-1;
index(n).keep=indx;
end
end
% calculate intervals...
I = zeros(NT,max(NI));
IT = [];
for n=1:NT
I(n,1:NI(n)) = diff(data(index(n).keep,n));
IT = [IT I(n,1:NI(n))];
end
Mx = max(IT);
if Nbins == -1
Nbins = floor(sum(NI)/30);
Med = median(IT);
Nbins = max(floor(Nbins*Mx/Med),10);
end
B = linspace(0,Mx,Nbins);
N = zeros(NT,Nbins);
for n=1:NT
N(n,:) = hist(I(n,1:NI(n)),B);
end
% answer...
if NT > 1;Ns = sum(N)/NT;else Ns = N;end
if ~strcmp(plt,'n')
bar(B,NT*Ns);
end
% Jackknife iver trials to estimate std...
if NT > 4 && err == 1
MN = 0;
SN = 0;
for n=1:NT
JK = (NT*Ns - N(n,:))/(NT-1);
MN = MN + JK;
SN = SN + JK.^2;
end
MN = MN/NT;
SN = SN/NT;
E = sqrt((NT-1)*(SN - MN.^2));
if ~strcmp(plt,'n')
hold on
errorbar(B,NT*Ns,NT*2*E,'r-')
hold off
end
end
N = NT*Ns;
3 件のコメント
Hank
2019 年 11 月 13 日
What data are you passing. It looks like the way you're trying to spoof the function isn't working. Notice that the function checks the number of input arguments, nargin. Even though you defined data, it throws an error since you passed no arguments. Try running isi(0). This will spoof it into seeing nargin=1 but then the code will use your hardcoded data and disregard the 0.
致远 马
2023 年 2 月 17 日
Have you solved this problem? I have the same problem now. Do you have ISI code now,thankyou!
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で JSON Format についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!