MATLAB: Import txt file containing some comment character = “#” import txtMATLAB Hi all, I want to import an txtfile containing in the middle of the file some lines with a comment character "#". Thank you in advance, Best Answer Mention: ....'CommentStyle','#')fileID = fopen(filename); %an example C = textscan(fileID,formatspec','Delimiter',',','CommentStyle','#');fclose(fileID); Related SolutionsMATLAB: How to read a CSV file with header The better way was use the textscan function with ";" delimiter and after replace the "," by "." before the conversion of string to number.fileID = fopen(filename,'r');startRow = 10;dataArray = textscan(fileID,'%s%s%s',inf,'Delimiter',';',... 'HeaderLines', startRow-1,'ReturnOnError', false);fclose(fileID);dataArray{1,2} = strrep(dataArray{1,2},',','.');dataArray{1,3} = strrep(dataArray{1,3},',','.'); MATLAB: Issue regarding reading .txt file with comments If you are using textscan() to read in the data, you can use the 'CommentStyle' property which will ignore any text on a single line following the comment character ('#').A simple examplefid = fopen('test1.txt'); C = textscan(fid, %f, 1, 'CommentStyle', '#'); fclose(fid); Related QuestionSlash / after text .txtIgnoring comments when parsingInvalid expression in reading the fileMerging ps_comments.db
Best Answer