How to filter tables in the cell?

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

 Akzeptierte Antwort

Akira Agata
Akira Agata am 10 Apr. 2020

1 Stimme

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 Kommentar

BN
BN am 11 Apr. 2020
Really thank you both answers are perfect.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 10 Apr. 2020

1 Stimme

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.

Kategorien

Produkte

Gefragt:

BN
am 9 Apr. 2020

Kommentiert:

BN
am 11 Apr. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by