Readtable: Invalid parameters name
28 views (last 30 days)
Show older comments
I am trying use readtable() function to read simple text file, however I keep geting all sorts of "Invalid parameter name" errors.
I call the function this way:
table = readtable(fileName, ...
'FileType', 'text', ...
'ReadRowNames', false, ...
'MissingRule', 'omitrow', ...
'ImportErrorRule', 'error', ...
'ReadVariableNames', false, ...
'ExpectedNumVariables', 6, ...
'Delimiter', ' ', ...
'NumHeaderLines', 2, ...
'Format', '%u32%u16%u16%u16%u32%u16', ...
'Encoding', 'ISO-8859-1' ...
)
And the errors I get are:
Error using readtable (line 498)
Invalid parameter name: MissingRule.
Invalid parameter name: ImportErrorRule.
Invalid parameter name: ExpectedNumVariables.
I undestand I can use DelimitedTextImportOptions object, however as far as I know, this option does not support skipping columns by supplying Format in starred form (like '%*u32').
2 Comments
Geoff Hayes
on 21 Feb 2022
@Radek - what does your version of MATLAB say with respect to the three parameters that are invalid? Can you find them in the documentation for your version (which is?) or are you looking at the online MATLAB documentation?
Answers (2)
Cris LaPierre
on 21 Feb 2022
Edited: Cris LaPierre
on 21 Feb 2022
I believe the error is because these options are not valid when you specify 'Format'.
The section of code in readtable that generates this error begins with this line of code (names is your input parameter names)
if any(strcmpi(names,"Format"))
If I remove 'Format' from the options, I don't get any errors.
3 Comments
Cris LaPierre
on 21 Feb 2022
Possibly. If you use detectImportOptions, you can specify which variables to read in.
opts.SelectedVariableNames = {'Systolic','Diastolic'};
You do not have to use variable names. You can also specify the columns by number.
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!