I have a large number of .dat files in a folder sorted under names in the format "author_energy_radiationtype_cellline", and I am using the "dir" command to select the files that apply to particular energies, cell lines etc. Each .dat file has between 2 and 7 headerlines I want to skip. The files have the following format.
"SF(Dose (Gy)) created by Plot Digitizer 2.6.8""Date: 1/17/19 8:41:06 AM"author year mod cell_line energy let**** 2008 protons *** 6MV -$\mu$malpha alpha_err beta beta_err alpha_X alpha_X_err beta_X beta_X_err0.291 0.000 0.041 0.000 0.291 0.000 0.041 0.000 Dose (Gy) SF Error0.8312 0.7674 0.91211.8470 0.4560 0.56152.8600 0.2924 0.34574.8985 0.0761 0.12446.9425 0.0218 0.0344
I want to read the data under the 'Dose', 'SF', and 'Error' columns read into arrays, and I also need to extract the first and third values in the 6th row. Is there any way to do this when the number of headerlines changes from file to file?
This is my code so far. I can pick out the files with certain energies, etc. I can't seem to figure out how to actually extract the data in the way I described above.
% Specify the folder where files are located
myFolder = 'C:\Users\..\Desktop\CellSurvivalData';% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return;end% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*235MeV*HSG*'); % Define desired parameters
theFiles = dir(filePattern); % List the files which satisfy these parameters
for k = 1 : length(theFiles) baseFileName = theFiles(k).name; fullFileName = fullfile(myFolder, baseFileName); fprintf(1, 'Now reading %s\n', fullFileName); % Read the data from each file
file{k} = readtable( fullFileName );end
Best Answer