How ignore a string of characters?
    3 views (last 30 days)
  
       Show older comments
    
I would like define a set of files by using their names which are string of characters, for example:
LNC-CAT_26_ *170613* _run_bada_01.mat
LNC-CAT_26_ *072612* _run_bada_01.mat
LNC-CAT_26_ *045612* _run_bada_01.mat
...etc.
But, I also would like to ignore a little characters string (in blod) in these filenames because these little strings change every time.
my first lines of command are :
source = 'C:\Users\ALG\Desktop\2012_fMRI_LNCCAT\LNC_CAT\ba-da';
direction = 'C:\Users\ALG\Desktop\behavior_analysis';
sujets = {'03','05','08','11','14','15','17','21','26'};
for numsubj = sujets
    run1file = ['LNC-CAT_' cell2str(numsubj) '_' * '_run_bada_01.mat'];
    etc....
What function or command should I write instead of the star (last line) in order to ignore the bold string?
1 Comment
Answers (3)
  Roberto
      
 on 28 Apr 2014
        if the length of the numbers is always the same, you can try parsing the string via the subscripts:
newStr = [oldstr(1:11) oldstr(18:end) ] ;
  Roberto
      
 on 28 Apr 2014
        I'm assuming you have this string like this, but I didn't understand what is it that you want to do, anyway here's some code to give you ideas:
oldStr = 'LNC-CAT_26_170613_run_bada_01.mat';
sujets = {'03','05','08','11','14','15','17','21','26'};
for i = 1: numel(sujets)
  run1file1 = ['LNC-CAT_' sujets{i} '_run_bada_01.mat']
  run1file2 = [oldStr(1:8) sujets{i} '_' oldStr(12:end)]
end
disp(run1file1);
disp(run1file2);
  Roberto
      
 on 6 May 2014
        
      Edited: Roberto
      
 on 6 May 2014
  
      I don't know if i really got it this time, is this what you want to do?
    selDossier = uigetdir;  % ask for the folder
    cd(selDossier); % go to the folder
    currentFile = dir ; % read folder's content
    selectedFile = {} ;
    selectedSubject = {} ;
    selectedNumber = {} ;
    for i = 1:numel(currentFile) % look for files
        if ~currentFile(i).isdir % discard subfolders
            if strcmpi(currentFile(i).name(1:8),'LNC-CAT_') %starts 'LNC-CAT_'
                selectedFile{end+1} = currentFile(i).name ; %filename
                selectedSubject{end+1} = currentFile(i).name(9:10); %Sub number
                selectedNumber{end+1} = currentFile(i).name(12:17);                 
            end
        end
    end
    % now lets work with each selected file...
    for i = 1: numel(selectedFile)
        load(selectedFile{i}) ;
        disp(['Selected Subject: ' selectedSubject{i}]) ;
        disp([' Selected Number: ' selectedNumber{i}]) ;
        % this depends on what you want to do!!!
    end
0 Comments
See Also
Categories
				Find more on Characters and Strings in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

