MATLAB: How to open multiple .txt files text file Hi all, I have certin number of txt files with different names (ex: 5, 10, 15, 20, 25, 30, 35, 40, 80, 120, …) I want to open them using a loop. Any help would be appreciated. Best Answer If all the files have the same structure/data format, you can use datastore to merge them:fileNames = {'t1.txt', 't2.txt', 't3.txt'}ds = readall(datastore(fileNames)); % change other properties if neededotherwise, you can use readtable within a loopfileContents = {};fileNames = {'t1.txt', 't2.txt'};for i = 1:numel(fileNames) fileContents{i, 1} = readtable(fileNames{i});end Related SolutionsMATLAB: How work with Datastore from two or more file excel sheets Hi, I don't think that is possible using Datastore, but one possible workaround could be:path = 'Source';files = dir(fullfile(path, '*.xlsx'));result = table(); filecontent = readtable(fullfile(path, files(1).name)); filecontent2 = readtable(fullfile(path, files(2).name)); vars1 = [filecontent.Properties.VariableNames]vars2 = [filecontent2.Properties.VariableNames]R = {[vars1 vars2]}result = array2table([table2array(filecontent) table2array(filecontent2)],'VariableNames',R{:});Hope this helps! MATLAB: Import txt file containing some comment character = “#” Mention: ....'CommentStyle','#')fileID = fopen(filename); %an example C = textscan(fileID,formatspec','Delimiter',',','CommentStyle','#');fclose(fileID); Related QuestionDatastoreによりデータの読み込みSlash / after text .txtHow to select certain data from .txt fileConcatenate data using fgetsHow do i combine multible excel file into single file using matlab
Best Answer