The readtable command is not working and returns this error. Error using readtable (line 517) Unrecognized field name "text".
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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
Cris LaPierre
on 9 Dec 2024
Edited: Cris LaPierre
on 9 Dec 2024
Please share the result of the following:
which readtable
and
which readtable -all
Mike Croucher
on 9 Dec 2024
Can you share the .csv file?
Matteo Parodi
on 9 Dec 2024
Matteo Parodi
on 9 Dec 2024
Cris LaPierre
on 9 Dec 2024
Edited: Cris LaPierre
on 9 Dec 2024
I was curious because of this post: https://www.reddit.com/r/matlab/comments/10lgbiv/unrecognized_field_name_text_cannot_figure_out/
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')
Matteo Parodi
on 9 Dec 2024
Stephen23
on 9 Dec 2024
This is what occurs with R2024b on Win11:

I wonder if this has something to do with the OS.
Walter Roberson
on 9 Dec 2024
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.
Matteo Parodi
on 10 Dec 2024
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!