Description:
The function pop_importbids fails to correctly locate or parse datasets when the input path bidsfolder is provided as a MATLAB string (double quotes "..."), which is the default text type in modern MATLAB versions. It only functions correctly when the input is a char array (single quotes '...').
The current documentation header describes the input simply as [string], which is ambiguous in the context of modern MATLAB (where it usually implies the string class, but legacy code expects char).
Steps to Reproduce:
Provide a valid BIDS folder path as a double-quoted string.
Run pop_importbids.
% Assume valid BIDS folder at this path, we can clone one from OpenNeuro
bidsPath = "C:\data\my_bids_dataset"; % MATLAB string object
% This fails (crashes or returns 'No dataset found')
[STUDY, ALLEEG] = pop_importbids(bidsPath);
% This works
[STUDY, ALLEEG] = pop_importbids(char(bidsPath));
Root Cause Analysis:
The crash occurs due to legacy indexing logic that assumes character array behavior. Specifically, around line 605 inside the file loop:
% Existing code assumes eegFileRaw is char
infoData = bids_importjson([ eegFileRaw(1:end-8) '_' modality '.json' ], ...);
-
If char: eegFileRaw(1:end-8) correctly slices the filename string (removing the last 8 characters).
-
If string: eegFileRaw is a scalar string object (1x1). end evaluates to 1. The range 1:end-8 becomes 1:-7 (empty). This results in an empty array being passed to bids_importjson, causing downstream errors (e.g., "Index exceeds array elements" or file not found).
Suggested Fix:
- Documentation Update (Low Effort) Explicitly specify in the help section that inputs must be character arrays.
% Inputs:
% bidsfolder - [char array] Path to the BIDS folder (e.g., 'C:\data\exp').
% Do not use MATLAB string objects ("...").
- Robust Input Handling (Recommended) Add a simple cast at the beginning of
pop_importbids to ensure compatibility with modern MATLAB scripts without requiring user intervention:
if nargin > 0
bidsfolder = char(bidsfolder);
end
Additional Context on Type Dependency:
While this report focuses on pop_importbids, it is worth noting that string vs char incompatibilities appear to be systemic within the ecosystem invoked here. For example, if we write eegFileRaw = char(eegFileRaw) at line 604 (to fix the line 605 crash), downstream functions like pop_saveset may subsequently fail due to strict type checks (e.g., strcmpi failures on string properties). Explicit input sanitization (casting to char) at the entry point of pop_importbids would effectively shield the internal logic from these external type mismatches.
Description:
The function
pop_importbidsfails to correctly locate or parse datasets when the input pathbidsfolderis provided as a MATLABstring(double quotes"..."), which is the default text type in modern MATLAB versions. It only functions correctly when the input is achar array(single quotes'...').The current documentation header describes the input simply as
[string], which is ambiguous in the context of modern MATLAB (where it usually implies thestringclass, but legacy code expectschar).Steps to Reproduce:
Provide a valid BIDS folder path as a double-quoted
string.Run
pop_importbids.Root Cause Analysis:
The crash occurs due to legacy indexing logic that assumes character array behavior. Specifically, around line 605 inside the file loop:
If
char:eegFileRaw(1:end-8)correctly slices the filename string (removing the last 8 characters).If
string:eegFileRawis a scalarstringobject (1x1). end evaluates to 1. The range1:end-8becomes1:-7(empty). This results in an empty array being passed tobids_importjson, causing downstream errors (e.g., "Index exceeds array elements" or file not found).Suggested Fix:
pop_importbidsto ensure compatibility with modern MATLAB scripts without requiring user intervention:Additional Context on Type Dependency:
While this report focuses on
pop_importbids, it is worth noting thatstringvscharincompatibilities appear to be systemic within the ecosystem invoked here. For example, if we writeeegFileRaw = char(eegFileRaw)at line 604 (to fix the line 605 crash), downstream functions likepop_savesetmay subsequently fail due to strict type checks (e.g.,strcmpifailures onstringproperties). Explicit input sanitization (casting tochar) at the entry point ofpop_importbidswould effectively shield the internal logic from these external type mismatches.