The readtable command is not working and returns this error. Error using readtable (line 517) Unrecognized field name "text".

Good morning,
I am using version 2024b, and when I try to use readtable on a CSV file, I get the error mentioned above. I also tried with other tables, and the file is not corrupted. The function works correctly with the same file format on my laptop, where I have version 2023b.
I investigated the issue, and it seems the error originates in the readtable function at line:
514 t = func.validateAndExecute(filename,varargin{:});
where it returns a list of errors:
Error in matlab.io.internal.FastVarOpts>getOptsStructWithDefaults (line 874)
s = defaults.text;
^^^^^^^^^^^^^
Error in matlab.io.internal.FastVarOpts/getVarOptsStruct (line 199)
s{ii} = getOptsStructWithDefaults(types{idx(ii)},C{idx(ii)},obj.DefaultDatetimeLocale);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.text.internal.TabularTextReader/initTextParser (line 255)
optionsStruct = rdr.Options.fast_var_opts.getVarOptsStruct(1:numVars);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.text.internal.TabularTextReader (line 77)
rdr.initTextParser(args);
^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.internal.functions.DetectImportOptionsText/setVarNames (line 319)
rdr = matlab.io.text.internal.TabularTextReader(tempOpts, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.internal.functions.DetectImportOptionsText/getTextOpts (line 80)
opts = func.setVarNames(opts,supplied);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.internal.functions.DetectImportOptionsText/execute (line 34)
opts = func.getTextOpts(supplied);
^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.internal.functions.DetectImportOptions/execute (line 80)
opts = func.execute@matlab.io.internal.functions.DetectImportOptionsText(supplied);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.internal.functions.ReadTable/execute (line 35)
func.Options = func.execute@matlab.io.internal.functions.DetectImportOptions(supplied);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.io.internal.functions.ExecutableFunction/validateAndExecute (line 68)
[varargout{1:nargout}] = func.execute(supplied,additionalArgs{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Thank you very much for your attention and for any help you can provide

9 Comments

Please share the result of the following:
which readtable
and
which readtable -all
>> which readtable
/usr/local/MATLAB/R2024b/toolbox/matlab/iofun/readtable.m
>> which readtable -all
/usr/local/MATLAB/R2024b/toolbox/matlab/iofun/readtable.m
/usr/local/MATLAB/R2024b/toolbox/shared/io/general/+matlab/+io/@ImportOptions/ImportOptions.m % matlab.io.ImportOptions method
@Mike Croucher I believe you're right because if I remove all the data, the table is read correctly. I created a minimal table that it fails to read, where it correctly recognizes the header rows but not the first row of data.
They reported the same error message as you. They had another function called readtable on the path, so they were not calling the correct readtable function.
I'm not able to reproduce the error in R2024b. I tested here (Linux) as well as on my desktop version (Win11)
T = readtable('Untitled 1.csv')
T = 1x6 table
Project Individual AltId TimePoint InputIds freesurfer_6_0_0_aparc_thickness_GUID ________ ___________ _________ _________ ___________________________________________________ _________________________________________ {'nini'} {'333_333'} 2.223e+05 {'m00'} {'4vdfbvdb7-4sbfd6-4fabf-93baerfad-bbeafaaa42aber'} {'0aaberbcd-2aeb7-4aer-9aber-7abr4c38e4'}
It seems that it doesn’t recognize those cells that need to be interpreted as cells. Is there a way to reinstall this component without uninstalling and reinstalling all of MATLAB?
This is what occurs with R2024b on Win11:
I wonder if this has something to do with the OS.
That's odd. matlab.io.internal.FastVarOpts contains
persistent defaults
if isempty(defaults)
defaults.numeric = makeOptsStruct(matlab.io.NumericVariableImportOptions);
defaults.datetime = makeOptsStruct(matlab.io.DatetimeVariableImportOptions');
defaults.datetime.FillValue = complex(NaN,0);
defaults.duration = makeOptsStruct(matlab.io.DurationVariableImportOptions');
defaults.categorical = makeOptsStruct(matlab.io.CategoricalVariableImportOptions');
defaults.text = makeOptsStruct(matlab.io.TextVariableImportOptions');
defaults.logical = makeOptsStruct(matlab.io.LogicalVariableImportOptions');
end
and then has a switch() with
case 'char'
s = defaults.text;
s.FillValue = zeros(0);
The defaults.txt field is set in the isempty(defaults) block. For that field to have been skipped in the assignments, defaults would have to have been on-empty. But it is a persistent variable, local to the function, and nothing outside of that isempty() block writes to defaults
It would be worth putting in a breakpoint at the isempty() test and examining to see what defaults is.
Good morning. I have no idea why, but this morning it started working (I had tried restarting it yesterday as well). I don’t know what happened, but I hope it doesn’t happen again. I will close the question.
Thank you all very much.

Answers (0)

This question is closed.

Products

Release

R2024b

Asked:

on 9 Dec 2024

Closed:

on 10 Dec 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!