Working with Excel Tables and Importing them.
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
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?
댓글 수: 0
채택된 답변
  Walter Roberson
      
      
 2019년 8월 13일
        mask = ismember(YourTable.Properties.VariableNames, ListOfColumnsYouWant);
NewTable = YourTable(:,mask);
댓글 수: 2
  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 Exchange에서 Spreadsheets에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

