MATLAB: How to filter tables in the cell

cell arraysMATLABtable

Hey all, I have a 1×2 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

Best Answer

  • 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.