I have a folder containing around 300,000 files. I don't need to import all the files.
Problem: How can I import a range of files based on specific file name?
This is an extension on the problem I asked in another post, link: https://www.mathworks.com/matlabcentral/answers/587738-import-files-based-on-file-name#answer_488336
Problem example:
In the picture below I have a section of the files, which are all in the same folder. I only want to import the .data files. But I don't need all the .data files to be import only the last 5 of every serie.
% Select only .data file from the last time step of each simulation
Folder = uigetdir;files = dir(fullfile(Folder,'*.data*'));spl = regexp({files.name},'\.data\.','split','once');spl = vertcat(spl{:});vec = str2double(spl(:,2));[~,idx] = sort(vec);[~,idy,idz] = unique(spl(idx,1),'last');out = {files(idx(idy)).name};expData = cell(length(out),1);for i = 1:length(out) fid = fopen(fullfile(Folder,out{i}),'r'); %% Reading the data % Read all the data from the file
dataRead = textscan(fid,'%f %f %f %f %f %f %f %f %f %f %f %f %f %f','HeaderLines',1);end
This code only extracts the last .data file of every serie, but as I explained I want to have the last 5 files of every serie.
Best Answer