Info
This question is closed. Reopen it to edit or answer.
The readtable command is not working and returns this error. Error using readtable (line 517) Unrecognized field name "text".
7 views (last 30 days)
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
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.
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!