Filter löschen
Filter löschen

error using readtable with "opts" and "TreatAsEmpty" together

3 Ansichten (letzte 30 Tage)
lp2015
lp2015 am 28 Mär. 2018
Beantwortet: Jeremy Hughes am 28 Mär. 2018
Hi, I am trying to import an xlsx file to a table using the following command:
trial_table = readtable(xlsx_file_path, opts, 'TreatAsEmpty',{'.','NA'});
However, I get the following error:
Error using matlab.io.spreadsheet.SpreadsheetImportOptions/readtable (line 339)
'TreatAsEmpty' is not a recognized parameter. For a list of valid name-value pair arguments, see the documentation for readtable.
I read the documentation, and as far as I understand, 'TreatAsEmpty' should be a recognized name-value pair argument. In fact, when I used only the 'TreatAsEmpty' or the 'opts' input alone, the function worked!
trial_table = readtable(xlsx_file_path, 'TreatAsEmpty',{'.','NA'}); #this works
trial_table = readtable(xlsx_file_path, opts); #this works
trial_table = readtable(xlsx_file_path, opts, 'TreatAsEmpty',{'.','NA'}); #this does not work
trial_table = readtable(xlsx_file_path, 'TreatAsEmpty',{'.','NA'}, opts);#this does not work
From the readtable documentation page I understand that I am using a valid input:
Any ideas why this is not working? Thanks
  2 Kommentare
Star Strider
Star Strider am 28 Mär. 2018
How did you define ‘opts’?
lp2015
lp2015 am 28 Mär. 2018
opts = detectImportOptions(xlsx_file_path);
% set catgegorical variables
cat_vars = {'Rat_Name','student_Name', 'Rat_Decison'};
member_cat_var = ismember(cat_vars, opts.VariableNames);
cat_vars = cat_vars(member_cat_var);
opts = setvartype(opts, cat_vars, 'categorical');
% set logical variables
lgc_vars = {'AutoFixation','AutoReward', 'AutoRewardSound', 'AutoStart', 'FixationOnly', 'skip_Analyze', 'stable_fixation', 'succsessfullTrial', 'SecondChoice', 'ErrorChoiceSoundOn', 'RewardSound', 'EnableClueSoundInBothSide', 'EnableClueSoundInCorrectSide','EnableRightLeftMustEquals' };
member_lgc_vars = ismember(lgc_vars, opts.VariableNames);
lgc_vars = lgc_vars(member_lgc_vars);
opts = setvartype(opts, lgc_vars, 'logical');

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jeremy Hughes
Jeremy Hughes am 28 Mär. 2018
Hi,
Only a subset of the parameters in READTABLE are allowed with the options. Part of the reason is that, in the import options, you can set TreatAs_Missing_ per-variable.
opts = setvaropts(opts, _yourVars_, 'TreatAsMissing',{'.','NA'});
Hope this helps
Jeremy

Weitere Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by