MATLAB: Issue regarding reading .txt file with comments

loading text file comments

Hello, I am trying to load a 'txt' file and plot it. It has just 2 columns and multiple rows. I also have few rows which have comments which i can not remove. But when i load the file and plot it. it just plot the data till the row which has the 1st comment. After that it is not acknowledging or reflecting the data. What can be done for this? Please help me out. I am using 2018 version Thanks in advance.

Best Answer

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 example
fid = fopen('test1.txt');
C = textscan(fid, %f, 1, 'CommentStyle', '#');
fclose(fid);