When a file is opened in vim and Sublime Text on Mac, there is no extra header line. However, the MATLAB Editor does display an extra header line. This is probably what is throwing off the detection code. 'fgetl' and 'textscan' are interpreting the number of header lines differently.
Two workarounds exist:
1. You can use the following call for "textscan" function:
>> dataset = textscan(fid, '%f %f', 'HeaderLines', skipLines, 'CollectOutput', 1, 'EndOfLine', '\r\n');
2. Use "readmatrix" function instead:
dataset = readmatrix(filename);
x = dataset (:,1);
y = dataset (:,2);
Best Answer