I am reading in several files of the same name from all different folders based on the folder name. Here I have gathered a list of the paths for these files:
axialList = dir('*_A_*');for i = 1:length(axialList) folders{i} = strcat(axialList(i).folder,axialList(i).name);endfor i = 1:length(folders) axialFiles{i} = strcat(folders{i},'\specimen.dat');end
This gives me cells with all the file paths I want to read. Then I'm trying to put these names in a loop to read it. This worked before I put it in the loop:
FormatString = repmat('%f',1,7);for i = 1:length(axialFiles) fileID = fopen(axialFiles{i}); SortHeader = textscan(fileID,'%s',5,'delimiter','\n'); Data{i} = textscan(fileID,FormatString,'delimiter','\t'); Data{i} = cell2mat(Data{i}); fclose(fileID)end
Now that I have it reading in fileID in the loop, I get the error 'Invalid file identifier. Use fopen to generate a valid file identifier'. If instead I just put the file names in like here:
FormatString = repmat('%f',1,7);for i = 1:length(axialFiles)% fileID = fopen(axialFiles{i});
SortHeader = textscan(axialFiles{i},'%s',5,'delimiter','\n'); Data{i} = textscan(axialFiles{i},FormatString,'delimiter','\t'); Data{i} = cell2mat(Data{i});% fclose(fileID)
end
I get an empty cell array. Please help!
Best Answer