Working with Excel Tables and Importing them.

11 ビュー (過去 30 日間)
Minjun Seo
Minjun Seo 2019 年 8 月 12 日
コメント済み: Walter Roberson 2019 年 8 月 13 日
After I import the table from Excel, how can I make a new table with only the names of the columns that you input somewhere?

採用された回答

Walter Roberson
Walter Roberson 2019 年 8 月 13 日
mask = ismember(YourTable.Properties.VariableNames, ListOfColumnsYouWant);
NewTable = YourTable(:,mask);
  2 件のコメント
Minjun Seo
Minjun Seo 2019 年 8 月 13 日
編集済み: Minjun Seo 2019 年 8 月 13 日
Thank you, but If I wanted multiple columns, do I seperate each column with a comma?
Walter Roberson
Walter Roberson 2019 年 8 月 13 日
Here, YourTable stands for the name of your table. Properties and VariableNames are literal things to put in. ListOfColumnsYouWant would be a cell array of character vectors.
>> T = array2table(randi(9,4,3))
T =
4×3 table
Var1 Var2 Var3
____ ____ ____
2 5 8
9 8 9
2 8 5
3 2 7
>> T.Properties.VariableNames
ans =
1×3 cell array
{'Var1'} {'Var2'} {'Var3'}
>> ListOfColumnsYouWant = {'Var3', 'Var1'};
>> mask = ismember(T.Properties.VariableNames, ListOfColumnsYouWant);
>> NewTable = T(:,mask)
NewTable =
4×2 table
Var1 Var3
____ ____
2 8
9 9
2 5
3 7

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by