필터 지우기
필터 지우기

Readtable: Invalid parameters name

조회 수: 29 (최근 30일)
Radek
Radek 2022년 2월 21일
편집: Cris LaPierre 2022년 2월 21일
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
Geoff Hayes
Geoff Hayes 2022년 2월 21일
@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?
Radek
Radek 2022년 2월 21일
편집: Radek 2022년 2월 21일
I dont know what you mean exactly. I use online documentation, but I believe it is relevant to my Matlab version, and my Matlab version is v2021b. All the parameters are phrased correctly exactly according to the manual.

댓글을 달려면 로그인하십시오.

답변 (2개)

Cris LaPierre
Cris LaPierre 2022년 2월 21일
편집: Cris LaPierre 2022년 2월 21일
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
Cris LaPierre
Cris LaPierre 2022년 2월 21일
Possibly. If you use detectImportOptions, you can specify which variables to read in.
For example, in this example the following option is specified:
opts.SelectedVariableNames = {'Systolic','Diastolic'};
You do not have to use variable names. You can also specify the columns by number.
Radek
Radek 2022년 2월 21일
Thanks! I must have missed it in documentation, sorry.

댓글을 달려면 로그인하십시오.


Radek
Radek 2022년 2월 21일
Thanks to @Cris LaPierre I was able to finaly read data from text file with readtable(), while skipping particular columns.
The solution is following:
opts = delimitedTextImportOptions( ...
'NumVariables', 3, ...
'VariableNames', {'name1', 'name2', 'name3',}, ...
'VariableTypes', {'uint8', 'uint16', 'uint32'}, ...
'Delimiter', {' '}, ...
'MissingRule', 'omitrow' ...
)
options.SelectedVariableNames = [1,3] % select columns here
table = readtable('./data.txt', opts)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by