I have this function to read my file but I need a loop to import all of them at once from one folder with the same format.
function cell1 = importfile2(filename, dataLines)%IMPORTFILE2 Import data from a text file
% CELL1 = IMPORTFILE2(FILENAME) reads data from text file FILENAME for
% the default selection. Returns the data as a table.
% CELL1 = IMPORTFILE2(FILE, DATALINES) reads data for the specified row
% interval(s) of text file FILENAME. Specify DATALINES as a positive
% scalar integer or a N-by-2 array of positive scalar integers for
% dis-contiguous row intervals.
% Example:
% cell1 = importfile2("C:\Users\admin\Desktop\all data\ty_1.DAT", [7, Inf]);
%% Input handling
% If dataLines is not specified, define defaults
if nargin < 2 dataLines = [7, Inf];end%% Setup the Import Options
opts = delimitedTextImportOptions("NumVariables", 7);% Specify range and delimiter
opts.DataLines = dataLines;opts.Delimiter = " ";% Specify column names and types
opts.VariableNames = ["VarName1", "Date", "VarName3", "VarName4", "VarName5", "VarName6", "VarName7"];opts.VariableTypes = ["double", "double", "double", "double", "double", "double", "double"];opts.ExtraColumnsRule = "ignore";opts.EmptyLineRule = "read";opts.ConsecutiveDelimitersRule = "join";opts.LeadingDelimitersRule = "ignore";% Import the data
cell1 = readtable(filename, opts);end
Best Answer