Search code examples
matlabcell-array

Why do I get a 0x1 cell? Matlab what function


I'm using the following code to look through all files in a particular directory, and I'm getting some strange results. The point of the program is to do the following: I'm looking through a huge number (~7000+) of .mat files for each day between 6-20-2007 and 9-20-2007. What I'm looking to do is search through each of these folders and look at the .mat files, etc. However, for some reason I'm getting a 0x1 cell that doesn't make sense to me. Maybe someone with a better trained eye can see why?

jDate = strtok( dates(j).name, '.' );    % Or dates(j,1).name

tradeFolder = sprintf( 'TAQ Data\\trades unzipped\\%s.tar\\%s\\', jDate );    
tradeFiles = what(tradeFolder);
tradeMat = tradeFiles.mat;

quoteFolder = sprintf( 'TAQ Data\\quotes unzipped\\%s.tar\\%s\\', jDate );
quoteFiles = what(quoteFolder);
quoteMat = quoteFiles.mat;

(I have excluded the beginnings of the file paths since it includes my name). Anyways, how the data is saved is this: I extracted each day's worth of data and saved it to the folders listed above. Inside trades unzipped, for instance, will be a folder 20070620.tar, and inside that folder will be another folder named 20070620, and inside that folder is over 7000 .mat files. So....how come I'm getting a 0x1 cell for the tradeFiles.mat?

If anyone can help I'd greatly appreciate it.


Solution

  • A few comments

    1. Both sprintf lines you have (tradeFolder=... and quoteFolder=...) has two '%s' in the formatted string, while only one argument: jDate. This might cause undefined behavior.

    2. It is better to use fullfile to concatenate paths and file names.

    3. Although using what in this context is correct, you might want to double-check it using dir( fullfile( tradeFolder, '*.mat' ) );

    4. It is best not to use i and j as variables in Matlab.