MATLAB: Matlab can’t read .csv or .mat files

errorMATLAB

I am using Matlab 2016a on two computers, one with Mac (Mojave 10.14) and one with Windows (7 Professional). I try to run a script on the same file and keep getting different errors on different systems. Three examples:
1) load('code.mat')
– on Mac: loading with no problems;
– on Windows:
Warning: While loading an object of class 'table':
When constructing an instance of class 'table', the constructor must preserve the class of the returned
object.
The object warning refers to is loaded, but empty. I checked saving the object and its class was indeed 'table'.
2) newData = readtable('code.csv');
– on Mac: no problems;
– on Windows:
The class table has no Constant property or Static method named 'readFromFile'.
Error in readtable (line 143)
t = table.readFromFile(filename,varargin);
3) [~,~,rawDATA] = xlsread('code.csv');
– on Mac:
Error using xlsread (line 251)
Unable to read XLS file /.../1089.csv. File is not in recognized format.
– on Windows: no problems;
I ended up running different parts on different computers, but now I'm stuck with point 1. The rest of te code is prepared for Windows, so I simply have to load the .mat file correctly on Windows. Does anyone know why these things are happening and how to force correct execution of the functions? At least to the 1 problem on Windows?
I'd really appreciate some help.

Best Answer

On your windows computer, I suspect that you have a table.m file somewhere on your path shadowing the built-in table class. Get rid of it. To find the culprit:
which table -all
For point 3, xlsread on windows use excel to read files. On Mac, it can't use excel so is limited to the 'basic' mode of xlsread. I suspect that your csv file is too complex for the basic mode. However, since it's a csv file, you would be better off to read it with readtable which would work both on Windows and Mac and would be faster on windows (since it doesn't need to start excel).
Related Question