MATLAB: How to remove lines that starts either : and # using regexp MATLAB I am interested only to screen rows that starts with number or skip those rows that starts with : and # Any idea ? Best Answer filecontent = fileread('NameOfTheFile.txt');newcontent = regexprep(filecontent, '^[#:].$', '', 'lineanchors', 'dotexceptnewline');You can use textscan() on the string newcontent:numcols = 18fmt = repmat('%g', 1, numcols);datacell = textscan(newcontent, fmt, 'CollectOutput', 1);data = datacell{1}; Related SolutionsMATLAB: Read text file and store in .mat file fid = fopen('file1.txt');A= textscan(fid,'%s');fclose(fid);celldisp(A)save file2 A MATLAB: Problem with reading text file and making changes I have found the answer:M = dlmread('C:\Users\G\Desktop\topo.txt',' '); %replace path as appropriate M(:,1) = []dlmwrite('C:\Users\G\Desktop\myfile.txt',M,',') Related QuestionText file modification (remove blank line)How to modify a specific line in a text fileHow to convert data set into .dat
Best Answer