How to filter tables in the cell?
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
Hey all, I have a 1x2 cell array (C), containing tables. In each table, I have a column named season. rows in the season column include Winter, Spring, Summer, and Autumn. So I need to have 4 new cells that each one contains only one season data. Like this:
C_winter
C_Spring
C_Summer
C_Autumn
Where each one contains:
{30×3 table}    {30×3 table}    {30×3 table}
Please let me know how I can do that.
Thanks
댓글 수: 0
채택된 답변
  Akira Agata
    
      
 2020년 4월 10일
        How about the following?
C_Winter = cellfun(@(x) x(strcmp(x.season,'Winter'),:),C,'UniformOutput',false);
The same solution will be applicable to other seasons.
추가 답변 (1개)
  Walter Roberson
      
      
 2020년 4월 10일
        cellfun(@(T) splitapply(@(varargin) {table(varargin{:}, 'VariableNames', T.Properties.VariableNames)}, T, findgroups(T.season)), C, 'uniform', 0)
The result will be a cell array the same size of C, each entry of which is a cell array containing 4x1 tables, one table for each season.
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


