How to write loop in MATLAB?

EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadset('filename','M04_AD1.set','filepath','C:\\EEG_OVGU\\AD1\\');
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 250);
EEG = pop_saveset( EEG, 'M04_AD1d' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadset('filename','M05_AD1.set','filepath','C:\\EEG_OVGU\\AD1\\');
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 250);
EEG = pop_saveset( EEG, 'M05_AD1d' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadset('filename','M07_AD1.set','filepath','C:\\EEG_OVGU\\AD1\\');
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 250);
EEG = pop_saveset( EEG, 'M07_AD1d' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadset('filename','M08_AD1.set','filepath','C:\\EEG_OVGU\\AD1\\');
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 250);
EEG = pop_saveset( EEG, 'M08_AD1d' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadset('filename','M10_AD1.set','filepath','C:\\EEG_OVGU\\AD1\\');
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 250);
EEG = pop_saveset( EEG, 'M10_AD1d' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadset('filename','M12_AD1.set','filepath','C:\\EEG_OVGU\\AD1\\');
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 250);
EEG = pop_saveset( EEG, 'M12_AD1d' );
EEG = eeg_checkset( EEG );

 Accepted Answer

set_numbers = [4, 5, 7, 8, 10, 12];
for K = set_numbers
setname_in = sprintf('M%02d_AD1.set', K);
setname_out = sprintf('M%02d_AD1d', K);
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadset('filename', setname, 'filepath', 'C:\\EEG_OVGU\\AD1\\');
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 250);
EEG = pop_saveset( EEG, setname_out );
EEG = eeg_checkset( EEG );
end

10 Comments

EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M01_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
EEG = pop_saveset( EEG, 'M01_ED1' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M03_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
EEG = pop_saveset( EEG, 'M03_ED1' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M04_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
EEG = pop_saveset( EEG, 'M04_ED1' );
EEG = eeg_checkset( EEG );
About this above script, I change
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M01_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
into
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\setname_in'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
Why it does not work? how can I correct it? Thank you very much!
EEG = pop_mffimport({fullfile('C:\EEG_OVGU\ED1', setname_in)}, {'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
set_numbers = [1, 3, 4];
for K = set_numbers
setname_in = sprintf('M%02d_ED1', K);
setname_out = sprintf('M%02d_ED1.set', K);
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_mffimport({fullfile('C:\EEG_OVGU\ED1',setname_in)},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
EEG = pop_saveset( EEG, setname_out );
EEG = eeg_checkset( EEG );
end
I need to change mff.file into set.file. But the script does not work.
The error in the MATLAB is:
Error using javaObject
No constructor with appropriate signature exists in Java class com.egi.services.mff.api.MFFResourceType
Error in mff_importsignal (line 61)
signalresourcetype = javaObject('com.egi.services.mff.api.MFFResourceType', javaMethod('valueOf',
'com.egi.services.mff.api.MFFResourceType$MFFResourceTypes', 'kMFF_RT_Signal'));
Error in mff_import (line 85)
[floatData, allDataSize, srate, nchans] = mff_importsignal(mffFile);
Error in pop_mffimport (line 84)
EEGTMP = mff_import(fileName{iFile});
Did pop_mmfimport ever work for you?
At the moment it looks to me as if possibly you do not have the Java .jar for mff . But as I do not know anything about mff, another plausible case is that you do have the .jar but that the code relies upon a server being available that is not available.
Which MATLAB release are you using?
Yes. the pop_mffimport is work for the single data.
such as
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M01_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
EEG = pop_saveset( EEG, 'M01_ED1' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M03_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
EEG = pop_saveset( EEG, 'M03_ED1' );
EEG = eeg_checkset( EEG );
EEG.etc.eeglabvers = '2020.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M04_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
EEG = pop_saveset( EEG, 'M04_ED1' );
EEG = eeg_checkset( EEG );
but I want to warite a loop to run them at the same time. It does not work.
My MATLAB version: R2020a, EEGLAB version: v2020.0
Please put in a breakpoint at the beginning of the failing pop_mffimport line that is currently
EEG = pop_mffimport({fullfile('C:\EEG_OVGU\ED1',setname_in)},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
and ask to display
{fullfile('C:\EEG_OVGU\ED1',setname_in)}
and compare that to
{'C:\EEG_OVGU\ED1\M01_ED1'}
I am very sad that the error occurred when I import the single data. I am very confused. Do you have some good advice that I can solve it? Thank you very much.
Error using javaObject
No constructor with appropriate signature exists in Java class com.egi.services.mff.api.MFFResourceType
Error in mff_importsignal (line 61)
signalresourcetype = javaObject('com.egi.services.mff.api.MFFResourceType', javaMethod('valueOf',
'com.egi.services.mff.api.MFFResourceType$MFFResourceTypes', 'kMFF_RT_Signal'));
Error in mff_import (line 85)
[floatData, allDataSize, srate, nchans] = mff_importsignal(mffFile);
Error in pop_mffimport (line 84)
EEGTMP = mff_import(fileName{iFile});
Okay, but I need the answer to what I asked above:
If your line
EEG = pop_mffimport({'C:\EEG_OVGU\ED1\M01_ED1'},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
works for you, and if executing the line a second time also works for you (sometimes there are problems that only occur the second time you do something), then please put in a breakpoint at the beginning of the line
EEG = pop_mffimport({fullfile('C:\EEG_OVGU\ED1',setname_in)},{'code','description','label','mffkeys','mffkeysbackup','name','relativebegintime','sourcedevice','tracktype'});
and when you stop at the breakpoint, ask to display
{fullfile('C:\EEG_OVGU\ED1',setname_in)}
and copy and paste the result here for us to look at.
Then in the editor window, click on the "Step" button to have it execute that line. Does it fail the first time through? If not, then continue running, stopping at that line each time and displaying
{fullfile('C:\EEG_OVGU\ED1',setname_in)}
before Step, and tell us how many of the calls to pop_mmfimport work and tell us which file it fails for.
Thank you so much for your help!!!!!!
I set a breakpoint, but MATLAB isn't stopping at the breakpoint.
In addition, I don't see the Step button in the editor.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!