Processing mutiple txt files from subfolders

1 Ansicht (letzte 30 Tage)
XASNewbie
XASNewbie am 2 Apr. 2017
Kommentiert: Image Analyst am 3 Apr. 2017
Hello,
I am new to Matlab and so would like to ask for your help in modifying a routine:
Under this current routine, I am required to input individual txt files placed in specific folder directories and run the function. Naturally, all analyses results are saved in the same folder containing the txt file. Then, to process the others I need to move to another folder and rerun the routine. This proves to be really time consuming since I have quite a lot of samples and references to run...
Is there a way to modify the routine so that I can simply input a folder, then it will search for all the txt files placed in the subfolders, apply the Wavelet analysis on each one of the txt files, and save each analysis result (matrices, images, fig files) to the subfolder containing the txt file?
I tried consulting these threads: https://fr.mathworks.com/matlabcentral/answers/245959-how-to-read-text-files-from-different-sub-folders-in-a-folder
and modified the "input ascii file" section of the routine above, to no avail...
I hope my problem is clear enough. I'd appreciate any advice/help, thanks in advance!

Antworten (1)

Image Analyst
Image Analyst am 2 Apr. 2017
You can use dir() with two asterisks if you have a later version of MATLAB. See attached demo. If you don't then you can use genpath() to get files in all subfolders. I've attached a demo for that too.
  2 Kommentare
XASNewbie
XASNewbie am 2 Apr. 2017
Hi there, thank you for your reply.
I tried to copy and paste this demonstration (in R2015b), and I am getting an error which says:
Error in genpath (line 17) allSubFolders = genpath(topLevelFolder);
The only change I did was change this line:
filePattern = sprintf('%s/*.*', thisFolder)
to
filePattern = sprintf('%s/*.txt', thisFolder)
Also, if I understood correctly, this code is meant to locate the txt files contained in the subfolders. But I can't seem to implement the wavelet analysis code to each of the txt file. From the previous thread, I should place the wavelet analysis code in the innermost for loop. However, the input part of the wavelet analysis code always opens a dialogue box which tells me to input a specific txt file.
The following is the input code of the wavelet analysis:
[fichier, path] = uigetfile('*', 'Enter normalized EXAFS spectrum: ');
fid = fopen(fichier,'r');
[A,count] = fscanf(fid,'%g %g',[2 inf]); A = A';
kold = A(:,1); xold = A(:,2); status = fclose(fid);
% removing extension quand besoin est
if findstr(fichier,'.')
fichier = fichier(1:findstr(fichier,'.')-1);
end
How would I be able to modify this part of the wavelet code so that it implements the loop?
Thanks a lot for your help.
Image Analyst
Image Analyst am 3 Apr. 2017
Post your code. You did something else. That line of code was line 43 in my demo, not line 17 like you had. Anyway, I changed that line to *.txt and it worked beautifully. You must have messed it up some other way.
And if anything before line 17/43 has wavelet stuff in it, I can't run that since I don't have the wavelet toolbox.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Applications finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by