how to find files in a directory with a list of strings froma a matrix
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix with a few list of characters and I'm trying to find the files with similar name in a directory to load. I can't get this code to work correctly.
u = {'IC','IH'};
myFolder = 'C:\Users\Desktop\Jar'
filePattern = fullfile(myFolder, 'u');
matFiles = dir(filePattern)
for k = 1:length(matFiles)
baseFileName = matFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
matData(k) = load(fullFileName);
end
0 Commenti
Risposta accettata
Stephen23
il 19 Apr 2017
Have a look at the output of this operation:
>> myFolder = 'C:\Users\Desktop\Jar';
>> filePattern = fullfile(myFolder, 'u')
filePattern =
C:\Users\Desktop\Jar\u
You joined the string 'u' onto the end of the filePattern, as if it were a foldername. Is this the effect that you desired?
If you want to use both of the strings in the cell array u, then you will have to do them one-at-a-time in a loop, and merge the results together.
Also note that you need to learn how to debug. Many beginners write code and rely only on what they imagine/wishfor/want/believe/assure/... about what their code is doing. But code does not care what is in your head, and it is your job to check what the code is actually doing. In your case it is easy because you only have a few operations and the string outputs can be checked quit trivially by hand. Always check what you code is actually doing, do not rely on what you think it is doing.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!