MATLAB: Issue when reading csv file using textscan()

errorMATLABtextscan

I want to read dataset.csv in my program. I have the following code:
filename = 'dataset.csv';
delimiter = '\t';
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false);
fclose(fileID);
However, I get this error:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Can someone tell me the issue? I couldn't spot it!!

Best Answer

You forgot to include the csv file so we're all going to be guessing here until you do. If you want a fast answer, you should attach the csv file so we can see what's wrong with it.
If the delimiter is a tab, then it's not a csv file despite the extension of csv that you incorrectly gave it. So you can't use csvread(). I suggest you try dlmread(). If you have headerlines, dlmread() now lets you specify how many header lines to skip by specifying the proper starting row and column.