Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Combine variable length vectors into one vector
Date: Thu, 16 Aug 2012 16:06:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 48
Message-ID: <k0j5pg$aob$1@newscl01ah.mathworks.com>
References: <k0c1vj$2h3$1@newscl01ah.mathworks.com> <k0c5do$9t1$1@speranza.aioe.org> <k0c8lb$o7s$1@newscl01ah.mathworks.com> <k0cbr3$l8l$1@speranza.aioe.org> <k0ce5i$d4d$1@newscl01ah.mathworks.com> <k0ck1g$31s$1@speranza.aioe.org> <k0do6p$gp9$1@speranza.aioe.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1345133168 11019 172.30.248.38 (16 Aug 2012 16:06:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 16 Aug 2012 16:06:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3536503
Xref: news.mathworks.com comp.soft-sys.matlab:776604

^^^^Ah, thanks.

You were right about the speed. So, what I ended up doing was going with your original suggestion (in the previous post). I just performed the concatenation when I defined the vectors themselves.i.e. at that step the vector was available, so I just used it rather than using filenames. This was much easier than working with cells containing the filenames. Your previous post worked exactly as expected. That was really all I needed. Thanks for this.

I've got another question. This is about loading filenames into a cell array. Specifically, it is about auto pre-allocating a cell.

BACKGROUND:
I've got a cell array that loads a certain set of files (based on the filenames) the first time through a loop. The second time, it loads a different set of files.

EXAMPLE of what is happening:
A file named "List.txt" is provided with the contents being:
a1bc
d1ef
g1hi

Then the loop does the following (loads files with one of these 3 strings in their filenames):
ex. i = 1 --> dataa1bc1.txt, dataa1bc2.txt, dataa1bc3.txt, dataa1bc4.txt
 i = 2 --> datad1ef1.txt, datad1ef2.txt, datad1ef3,.txt datad1ef4.txt
 i = 3 --> datag1hi1.txt, datag1hi2.txt, datad1ef3.txt, datad1ef4.txt

DESCRIPTION OF THE PROBLEM:
Now, look at line three (i = 3). The problem is that for the third iteration, there are only two files that should be loaded into the cell, not 4. So, the cell should shrink from 4 X 1 (for i = 1 and i = 2) to 2 X 1 for i = 3. Unfortunately, this isn't happening. So for i = 3, the cell holds 2 correct filenames (the first 2) and 2 incorrect filenames (the last 2).
------------------------------------------X------------------------------------------

Here is the actual code:

fid_1=fopen('List.txt');
nnn=textscan(fid_1,'%s');
fclose(fid_1);

for abcd=1:numel(nnn{1});
    filess = dir(['*' char(nnn{1}(abcd)) '*L*.txt'])
    spec_fc_row=1;
      for kk = 1:numel(filess);
         file=filess(kk).name;
         M{spec_fc_row,1}=filess(spec_fc_row).name;
         spec_fc_row=spec_fc_row+1;
      end
end
------------------------------------------X------------------------------------------

QUESTION:
As you can imagine, the next step involves loading the contents of the cell, one row at a time. Well this works well for i = 1 and i = 2 (assuming that numel(nnn{1}) = 3...though this number is not known ahead of time so pre-allocating using cell() is a problem), but for i = 3, 2 wrong filenames are being loaded as I mentioned above. Is there a way to auto shrink the cell array size? Or is there a more effective (alternative) way to load these files?

PS: In the code above, f the line starting with filess, n contains:
'a1bc'
'd1ef'
'g1hi'