quantifySpikeWaveform code
Function unable to retrive spike_shape data from Spike shape function (M)
9 views (last 30 days)
Show older comments
In the following code I am trying to enable my function to retrive spike-shape data that are the results of another function called M. However, for an unknown reason it doesnt read that function and cannot retrive those data to go to the next steps of the code: See below please: I get errors like the following:
Unrecognized field name "maxAmpASamp".
Error in Fig_RN_Shape_v4 (line 82)
AHPSamp(h) = M(h).maxAmpASamp; % calculation based on Fig_LC code
maxAmpASamp and the rest are present in M.
function [A,ampDCList,FilesNotFound,STATS,as,alme] = Fig_RN_Shape_v4
S = RNDataStruct;
ampDCList = [0.5 1 2 3];
nCols = 1;
nucleusCode = 'RN';
getSpikeWaveforms = 1;
doPlot = 1;
fs = 30e3;
preTime = -5e-3;
postTime = 10e-3;
preSamp = round(preTime*fs);
postSamp = round(postTime*fs);
sampVec = [preSamp:postSamp];
tvec = sampVec/fs;
%%
nAmps = length(ampDCList);
for n = 1:nAmps
eval(['A.A' num2str(n) '= [];'])
end
FilesNotFound = [];
i=1;
ii = 0;
for n = 1:length(S)
if S(n).isSpikedSorted == 1;
for m = 1:length(S(n).fileListDC)
dataFolder = [S(n).dataPath S(n).fileListDC{m}];
nChans = S(n).nChans;
dataFolder = unixCheckPath(dataFolder);
phyFolder = [dataFolder filesep 'continuous_filt' filesep 'continuous_filt.GUI'];
% get the cluster Info FileName
clusterInfoFileName = [phyFolder filesep 'cluster_info.tsv'];
if exist(clusterInfoFileName, 'file')
phySpikeFile = [dataFolder '\' S(n).fileListDC{m} '.physpks'];
if exist(phySpikeFile, 'file')
disp(['Loading ' phySpikeFile])
load(phySpikeFile,'-mat')
else
I = getPhySpikeTimes(dataFolder,getSpikeWaveforms,nChans);
disp(['Saving ' phySpikeFile])
save(phySpikeFile,"I")
end
M = struct();
for o = 1:length(I)
ii = ii + 1;
if isfield(I(o), 'avgSpike') % Check within the current element I(o)
avgSpike = I(o).avgSpike - min(I(o).avgSpike);
avgSpike = avgSpike / max(avgSpike);
M(ii) = quantifySpikeWaveform(I(o).avgSpike, I(o).tvec, doPlot);
end
end
if ~isempty(I)
I = analysePhySpikeTimes(I,0);
for h = 1:length(I)
I(h).ratName = S(n).ratName;
I(h).ratNumber = str2num(I(h).ratName(4:5));
end
A.A1 = I; %% arbitrary
if ~isnan(I(1).ampDC)
indAmp = find(I(1).ampDC(1) == ampDCList);
if ~isempty(indAmp)
eval(['A.A' num2str(indAmp) '= [A.A' num2str(indAmp) ' I];'])
end
end
end
else
FilesNotFound{i} = clusterInfoFileName;
i = i + 1;
end
end
end
end
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%5HT-Neurons-Filtering
filteredNeurons = [];
B = A.A1;
for h = 1:length(B)
AHPSamp(h) = M(h).maxAmpASamp; % calculation based on Fig_LC code
TroughSamp(h) = M(h).minAmpSamp; % calculation based on Fig_LC code
TroughAHPDur(h) = M(h).tvec(AHPSamp(h)) - M(h).tvec(TroughSamp(h)); % calculation based on Fig_LC code
if B(h).spikeRatePreMean >= 1 && B(h).spikeRatePreMean <= 5
if B(h).spikeRateDurMean >= 1 && B(h).spikeRateDurMean <= 5
if B(h).spikeRatePostMean >= 1 && B(h).spikeRatePostMean <= 5
if TroughAHPDur(h)*1e3 >= 1 % I am not certain whether TroughAHPDur(h)*1e3 gives spike duration in ms; please double-check
filteredNeurons = [filteredNeurons B(h)];
end
end
end
end
end
A.A1 = filteredNeurons;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 Comments
Walter Roberson
on 12 Jul 2024 at 19:56
Please read http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval for information about why we strongly recommend against creating variable names dynamically.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!