help > Assistance Required for Persistent MATLAB Error: "Unable to write file: Invalid argument
Dec 6, 2024  12:12 AM | Junhyeok JAng
Assistance Required for Persistent MATLAB Error: "Unable to write file: Invalid argument

Dear Alfonso,

I am encountering a recurring issue while running the following MATLAB code in the CONN Toolbox during the preprocessing pipeline. Despite troubleshooting efforts, the error persists.


Code in Use


The error arises when running the following preprocessing code:



matlab






% CONN Project Setup
batch.filename = fullfile('C:\Users\MIDASIT\Neurocompetency_project\Korea_univ\my_project');
batch.Setup.isnew = 1;
batch.Setup.nsubjects = NSUBJECTS;
batch.Setup.RT = TR;

batch.Setup.structurals = STRUCTURAL_FILE;
batch.Setup.functionals = repmat({{}}, [NSUBJECTS, 1]);

for nsub = 1:NSUBJECTS
for nses = 1:nsessions
batch.Setup.functionals{nsub} = {FUNCTIONAL_FILE{nsub}};
end
end

batch.Setup.covariates.names = {'nuisance regressor'};
for nsub = 1:NSUBJECTS
for nses = 1:nsessions
if ~isempty(COVARIATE_FILE{nsub})
batch.Setup.covariates.files{1}{nsub} = COVARIATE_FILE{nsub};
else
batch.Setup.covariates.files{1}{nsub} = [];
end
end
end
conn_batch(batch);

% Preprocessing pipeline
addpath('C:\Users\MIDASIT\neuroimaging\spm12');
addpath('C:\Users\MIDASIT\neuroimaging\conn');
cwd = cd('C:\Users\MIDASIT\Neurocompetency_project\Korea_univ');
load my_project;

batch.Setup.preprocessing.steps = 'default_mni';
batch.Setup.preprocessing.sliceorder = 'interleaved (Siemens)';
batch.Setup.done = 1;
batch.Setup.overwrite = 'Yes';

conn_batch('Setup.preprocessing.steps', 'default_mni');


Error Message


파일 C:\Users\MIDASIT\Neurocompetency_project\Korea_univ\20240509_001\20240509_001\rsfmri\rsfmri_orig.mat을(를) 쓸 수 없음: Invalid argument.


오류 발생: write_extras (28번 라인)
save(mname,'-struct','extras', opt);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
오류 발생: nifti/create (29번 라인)
    write_extras(fname,o.extras);
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
오류 발생: spm_get_space (51번 라인)
    create(N);
    ^^^^^^^^^
오류 발생: conn_setup_preproc (4057번 라인)
                                spm_get_space(temp{n},M{n});
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
오류 발생: conn_process (6040번 라인)
    conn_setup_preproc(varargin{:});
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
오류 발생: conn_process (66번 라인)
            case 'setup_preprocessing', conn_disp(['CONN: RUNNING SETUP.PREPROCESSING STEP']); conn_process(35,varargin{:});
                                                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
오류 발생: conn_batch (1331번 라인)
                conn_process('setup_preprocessing',steps,'subjects',SUBJECTS,OPTIONS{:});
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Steps Taken


I have verified that directory configurations are not the cause of this issue by successfully saving files to the same directories:



matlab






dummy_data = [1 2 3];
save('C:\Users\MIDASIT\Neurocompetency_project\test_file.mat', 'dummy_data');
save('C:\Users\MIDASIT\Neurocompetency_project\Korea_univ\20240509_001\20240509_001\rsfmri', 'dummy_data');


Additional troubleshooting steps include:



  1. Ensuring write permissions for all directories involved.
  2. Redirecting temporary directories to avoid OneDrive synchronization conflicts.
  3. Testing the code with different MATLAB and CONN Toolbox installations.
  4. Running the project files on an SSD to address potential HDD-related bottlenecks.



Request for Assistance


Could you please advise:



  1. Whether this error is a known issue with CONN Toolbox, SPM, or MATLAB?
  2. Any additional steps to identify or resolve .mat file saving errors in this context?
  3. Insights into environmental factors that might cause this issue despite correct permissions and directory configurations?



I recently started working at a new company where I am using this software for analysis. The company employs a strict security program as part of its internal network configuration. I wonder if certain security measures or restrictions (e.g., antivirus software, controlled folder access, or real-time monitoring) could interfere with MATLAB’s ability to save .mat files or perform certain write operations.



I would appreciate your guidance and assistance. If needed, I can provide additional logs or details.


Thank you for your time and support.


Best regards,
Junhyoek Jang
Department of Psychology,
Jeonbuk National University





Threaded View

TitleAuthorDate
Assistance Required for Persistent MATLAB Error: "Unable to write file: Invalid argument
Junhyeok JAng Dec 6, 2024
Alfonso Nieto-Castanon Dec 9, 2024
Junhyeok JAng Dec 10, 2024