identify different filname in different group
Show older comments
Hello,
I just realized a program that allows to load data files from a folder. These data files are all different names but I would group them into three groups in matlab. A group 1 whose file names begin with 'X', a group 2 whose file names begin with 'Y' and a group 3 whose file names begin with 'Z' but I do not know how. Do you have any idea? with strcmp?
Accepted Answer
More Answers (3)
pfb
on 17 Apr 2015
It's not very clear to me what you mean by "group the files in matlab".
Anyway, one possibility is perhaps to discriminate them before loading them. I suppose you use dir to make a list of the files to be loaded. Why don't you use something like
dirX = dir('X*');
dirY = dir('Y*');
dirZ = dir('Z*');
or something to that effect? I mean, you might have to refine the string you feed to dir(), possibly adding a path or using some more information about the file names.
Anyway, now dirX, dirY and dirZ are structures containing the names of the files starting with the desired letter.
Image Analyst
on 17 Apr 2015
0 votes
It is all there in the FAQ. Code samples and everything. Adapt as needed: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
Image Analyst
on 21 Apr 2015
Of course, because you're passing the whole structure:
file_name = contenu(file).name;
load(contenu) % Tries to load the entire structure of all filenames.
Instead, try to load only one filename:
file_name = contenu(file).name;
load(file_name) % Tries to load only one single filename.
4 Comments
Alexandre Williot
on 21 Apr 2015
Edited: Alexandre Williot
on 21 Apr 2015
Image Analyst
on 22 Apr 2015
file is no longer defined because the for loop over "file" has ended by the time you call your next if block in etape2. I guess you probably want it INSIDE your for loop, not outside.
Alexandre Williot
on 22 Apr 2015
Image Analyst
on 22 Apr 2015
By the way, you were supposed to accept my answer, not post your code and accept it.
Categories
Find more on Loops and Conditional Statements 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!