MATLAB: How to combine a file name together with a filename, sprintF

MATLABsprintf

Dear All,
I'm having trouble where I need to pull a number using P%0.2d, I think the issue is that P%0.2d doesn't start right after sprintf.
I've omited some of my file names because it is not relevant to solve the issue.
Participant=[1,2 ,3];
for ppt=1:numel(Participant);
oSubj=Participant(ppt);
D = spm_eeg_load ('filename',sprintf('XXX to XXX_XXX_P%0.2d_XXX_removed XXX_XXX.dat', oSubj),'filepath','C:\Matlab_DataX\fulldataX\');
end

Best Answer

Use square brackets to horizontally concatenate the various parts of the argument to ‘spm_eeg_load’:
D = spm_eeg_load(['filename',sprintf('XXX to XXX_XXX_P%0.2d_XXX_removed XXX_XXX.dat', oSubj),'filepath','C:\Matlab_DataX\fulldataX\']);
I did not test this with the function call (obviously, since I do not have the function), however the argument itself was:
'filenameXXX to XXX_XXX_P03_XXX_removed XXX_XXX.datfilepathC:\Matlab_DataX\fulldataX\'
for appropriate values of ‘oSubj’ (here 3).