Extract all columns from a table where the column names "start with" a string
    조회 수: 49 (최근 30일)
  
       이전 댓글 표시
    
How can I extract all columns from a table where the column names "start with" a string?
For example, in
mytable = array2table(NaN(4,5));
mytable.Properties.VariableNames = {'A1', 'A2', 'B1', 'F2', 'F4'};
How would I extract all the "F*" columns in to a new table?
댓글 수: 0
채택된 답변
  Walter Roberson
      
      
 2019년 8월 28일
        mask = startsWith( mytable.Properties.VariableNames, 'F');
Fcols = mytable(:,mask);
추가 답변 (1개)
  Arnaud Delorme
      
 2022년 5월 27일
        
      편집: Arnaud Delorme
      
 2022년 5월 27일
  
          colNames = fieldnames(mytable);
    [~,inds] = intersect(colNames, { 'A1' 'A2' } );
    mytable = mytable(:,sort(inds));
댓글 수: 1
  Walter Roberson
      
      
 2022년 5월 27일
				This would not get you anything that mytable(:, { 'A1' 'A2' } ) would not give, other than preserving relative order of variables.
참고 항목
카테고리
				Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

