MATLAB: Reading data from a file which include symbols. read a complex txt file I need to read the first column of the file attached and the last 3 digits of each line as a column. Appreciate any help. Best Answer t = regexp(fileread('Dst.txt'), '(\r)?\n', 'split');firstcol = regexp(t, '^\S+', 'match');last3 = regexp(t, '...$', 'match');first_last = [firstcol(:), last3(:)];first_last{1,1}, first_last{1,2} is the pair for the first line Related SolutionsMATLAB: How to import mixed .txt – file in a table, with text as comment on first 3 rows and then numeric data with headers Make it a two-step process!First, read the first comment lines using FOPEN and FGETL. See the help of FGETL for an example. Do not forget to close the file with FCLOSE.Two, read the rest of the file with READTABLE and use the HeaderLines option to skip the first comment lines. MATLAB: How to remove the first 2 lines from an ascii file You are doing it the hard way around. Easier isfid = fopen('filename');datacell = textscan(fid, '%f', 'HeaderLines', 2);fclose(fid);A = datacell{1}; Related QuestionHi there! I am working on a script that will convert an array with zeros into an array of symbols.How can i read second column from a txt file in matlabRegexp: \w* vs \w+Reading data from .txt file skipping lines and others
Best Answer