Function unable to retrive spike_shape data from Spike shape function (M)

1 回表示 (過去 30 日間)
Alireza Majdi
Alireza Majdi 2024 年 7 月 12 日
コメント済み: Alireza Majdi 2024 年 9 月 23 日
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 件のコメント
Alireza Majdi
Alireza Majdi 2024 年 7 月 12 日
quantifySpikeWaveform code
Walter Roberson
Walter Roberson 2024 年 7 月 12 日
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.

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

採用された回答

Ronit
Ronit 2024 年 9 月 20 日
Hello Alireza,
The issue you're encountering is likely due to the scope and persistence of the variable "M". In your code, "M" is being defined inside a loop, and it is not being stored or passed outside of that loop in a way that the later part of your code can access it.
To troubleshoot the error you're encountering, here are a few potential issues and solutions:
  • Initialization of "M": Ensure that "M" is correctly initialized and populated with data.
M = struct(); % Initialize M outside the loop
  • Debugging Output After Populating "M"
% Debugging: Check the fields of M(ii)
disp(['Fields of M(' num2str(ii) '):']);
disp(fieldnames(M(ii)));
  • Check if "M" is Not Empty Before Accessing Fields
if ~isempty(M)
  • Field Existence Check: Before accessing fields like "maxAmpASamp", verify that they exist in "M". Use “isfield” to check for the presence of these fields.
if isfield(M, 'maxAmpASamp') && isfield(M, 'minAmpSamp') && isfield(M, 'tvec')
AHPSamp(h) = M(h).maxAmpASamp;
TroughSamp(h) = M(h).minAmpSamp;
TroughAHPDur(h) = M(h).tvec(AHPSamp(h)) - M(h).tvec(TroughSamp(h));
These changes help ensure that "M" is correctly populated and accessed, with additional checks and debugging outputs to trace potential issues.
Please refer to this MATLABs documentation for more debugging techniques:
Please refer to the documentation of “isfield” for more details:
Hope it helps!

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by