MATLAB: How to group loaded .txt files on a single array or struct

stringstructtext file

I'm trying to compare some files' names to group them according to their date. it happens that I have data from 3 different equipment and I'm trying to compare the files' names to build a single array or struct without success.
I loaded the files using:
G = dir('GPS_*.txt');
for n = 1:length(G)
H = dir('HOB_*.txt');
for n = 1:length(H)
N = dir('NEF_*.txt');
for n = 1:length(N)
I have now the files loaded as:
G 12x1 struct
GPS_01122013_1 4846x11 double
GPS_02112013_1 3819x11 double
GPS_02112013_2 3820x11 double
H 12x1 struct
HOB_01122013_1 5226x9 double
HOB_02112013_1 3580x9 double
HOB_02112013_2 3826x9 double
N 13x1 struct
NEF_01122013_1 88x9 double
NEF_02112013_1 63x9 double
NEF_02112013_2 64x9 double
I tried to use strcmp (, but had no result. I wanna group by date to build a matrix for each day of data.
Thanks in advance for the help

Best Answer

  • That's because the names aren't the same; only the substring date_seqNo portion match--
    >> strcmp(,
    ans =
    If the prefix is always the fixed four characters, the above works ok.
    I think I'd approach it a little differently, however, by getting the first list and then processing it sequentially and returning the other files for the same date/sequence number.
    Sotoo (caution, aircode)...
    G = dir('GPS_*.txt');
    for ix=1:length(G)
    [~,nam]=fileparts(D(ix).name); % the name portion only
    dte=nam(5:end); % date string/sequence substr
    D=dir(['*' dte '.txt']); % get the three files that go together
    for jx=1:length(D) % and process them as a group as desired
    Will want to check that D is the right length and such niceties, of course, but that should simplify the problem I'd think...
    Actually, now that I think of it, since you know the prefix for the three types, once you've got G then you don't need to do a dir() for the others at all. Just process them by creating the names directly from the one by replacing the first three characters with the other two prefix strings sequentially.