MATLAB: To eliminate the lines begin with “%”

I have a file (attached here) which I need to eliminate all the lines begin with "%" and remove the "commas" after the numbers. Then read the numbers and put in separate columns X, Y and Z. Can anyone help me to make the program?

Best Answer

Hi!
Read in your file:
% read in a file
fid = fopen(FileName);
FC = textscan(fid, '%s', 'delimiter', '\n');
fclose(fid);
FC = FC{1};
You can get rid of all "%" lines if you compare the first char like:
FC = FC(~strncmp('%', FC, 1));
You can get rid of all ',' with a regex like:
FC = regexprep(FC, ',', '');
Afterwards you can parse your cell array FC line-by-line with sscanf to extract numbers.