-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from catalystneuro/Neuropixels/convert-locatio…
…n-to-be-readable-in-Python [Neuropixels] Add MATLAB script to convert "location" in "SU" struct to be readable in Python
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/constantinople_lab_to_nwb/schierek_embargo_2024/mat_utils/convertSULocationToString.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
% MATLAB script to process all .mat files in a specified directory, | ||
% checking for 'SU' structure and converting 'location' to a plain string if it exists | ||
|
||
% Specify the path to your directory containing the .mat files | ||
folderPath = '/Volumes/T9/Constantinople/Ephys Data/'; % Replace with your actual folder path | ||
|
||
% Get a list of all .mat files in the directory | ||
files = dir(fullfile(folderPath, '**', '*.mat')); | ||
matFiles = fullfile({files.folder}, {files.name}); | ||
|
||
% Loop through each .mat file in the directory | ||
for k = 1:length(matFiles) | ||
matFilePath = fullfile(folderPath, matFiles(k)); | ||
matFilePath = char(matFiles{k}); % Ensure it is a character array | ||
% Load the .mat file | ||
try | ||
data = load(matFilePath); | ||
catch ME | ||
% Handle the error | ||
disp(['An error occurred: ', ME.message]); | ||
continue | ||
end | ||
|
||
% Check if 'SU' structure exists in the loaded data | ||
if isfield(data, 'SU') | ||
SU = data.SU; % Get the SU structure | ||
numUnits = length(SU); | ||
|
||
% Iterate over each unit in the SU structure | ||
for i = 1:numUnits | ||
if isfield(SU{i}, 'location') | ||
% Check and convert location if it is a cell array | ||
if iscell(SU{i}.location) && ~isempty(SU{i}.location) | ||
locationStr = SU{i}.location{1}; % Extract first element if it is a cell | ||
else | ||
locationStr = SU{i}.location; | ||
end | ||
SU{i}.location = locationStr; | ||
end | ||
end | ||
|
||
S = data.S; | ||
save(matFilePath, 'S', 'SU'); | ||
disp(['Processed and saved: ', matFilePath]); | ||
% Clear variables to free up workspace | ||
clear SU; | ||
clear S; | ||
clear data; | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters