Error using load; Unable to read file matlab

2019-08-11 08:48发布

问题:

I am trying to open a dialog box that prompts the user to select a file and then using that file in a function written for a matlab toolbox called EEGLAB. The code is as follows:

[F,PathName,FilterIndex] = uigetfile({'*.*','All Files(*.*)'}, 'Select your File ')
b = strcat(PathName,F)
Input = importdata(b)
FF = Input.filename;
%Loading the dataset into EEG lab. and rereferencing to Cz. 
EEG = pop_loadset('filename','FF','filepath','/Users/maheensiddiqui/Desktop/eeglab13_4_4b/EEG_data/Data/infant control01 and lance01 ref Fz - TF Analysis - all electrodes/');
EEG = eeg_checkset( EEG );

The problem I am encountering is in this line:

EEG = pop_loadset('filename','FF','filepath','/Users/maheensiddiqui/Desktop/eeglab13_4_4b/EEG_data/Data/infant control01 and lance01 ref Fz - TF Analysis - all electrodes/');

and this is the error message I get:

Error using load Unable to read file '/Users/maheensiddiqui/Desktop/eeglab13_4_4b/EEG_data/Data/infant control01 and lance01 ref Fz - TF Analysis - all electrodes/FF': no such file or directory. Error in pop_loadset (line 108) TMPVAR = load('-mat', filename); Error in newrereferencing (line 7) EEG = pop_loadset('filename','FF','filepath','/Users/maheensiddiqui/Desktop/eeglab13_4_4b/EEG_data/Data/infant control01 and lance01 ref Fz - TF Analysis - all electrodes/');

Now if I don't do the popup dialog window in the beginning (meaning I delete the first 4 lines of code I have and in the following line I have:

  EEG = pop_loadset('filename','206301L01.set','filepath','/Users/maheensiddiqui/Desktop/eeglab13_4_4b/EEG_data/Data/infant control01

and lance01 ref Fz - TF Analysis - all electrodes/');

i.e. I explicitly state the name of the file, the rest of the code works fine. I am not sure why this is happening... I need to run my code for about 20 different files and its very inefficient if the name needs to be typed in each time for it to work! (Especially if I will be sharing my code with other people).

Does anyone know why I might be getting this error? Could it be because of the file format? .set rather than a conventional format like .mat or .txt or whatever. But the .set format works when the filename is put in explicitly. I have also changed my directory to exclude spaces but that doesn't work either...

I would appreciate any help!

回答1:

Thanks to Hoki's comment I was able to solve the problem. I was inputting the filename as a string when it was a variable.

EEG = pop_loadset('filename',FF,'filepath',...) using FF without 'FF' used it as the variable it was an fixed the problem.

Thanks Hoki.