Create new variable when movevar can't find a variable in a table.

2 ビュー (過去 30 日間)
John Doe
John Doe 2019 年 7 月 1 日
コメント済み: John Doe 2019 年 7 月 1 日
I am working on order processing data. I've imported all my data using readtable, done my processing and now need to order the data prior to export.
To do this I have used the below script. This works perfectly well.
t = movevars(t,varNames,'After','Column_1')
My challenge comes, if varNames contains a variable which is not in my data set, where I get an error.
I would like to compare varNames with the t.Properties.VariableNames and create new variables with NaNs or Zeros in t where there was not a variable in the table.
I can't come up with a sensible way to do this, my guess was using strcmp?

採用された回答

Steven Lord
Steven Lord 2019 年 7 月 1 日
Use ismember to determine if the variables you want to move/add are present in the table. The output from ismember will be a logical mask telling you which variable names you pass into movevars and which into addvars.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by