MATLAB: Finding cell array contents matching certain properties (e.g. dimensions)

cell arraysindexing

Afternoon,
I want extract cell array values that are of a specific dimension, and put into a new cell array.
Let v_yrs_farms be a 1x23x19 cell array, containing hourly wind speeds (data sets) at 19 different locations for 23 years. Some sites have missing data, and some years are leap years, therefore not all the datasets are of equal size. I want to extract all the data sets that is of size [8760×1] and save to a new cell array. Below is the structure of v_yrs_farms. Highlighted is examples of the contents that I wish to exclude form the new cell array.
Thanks in advance,
Leon.

Best Answer

Get the length os each cell and extract the cells of length you want. Check the below example code:
%%create random cell
A = cell(7,1) ;
A{1} = rand(3,1) ;
A{2} = rand(5,1) ;
A{3} = rand(5,1) ;
A{4} = rand(2,1) ;
A{5} = rand(5,1) ;
A{6} = rand(2,1) ;
A{7} = rand(1,1) ;
%%get the lengths of each cell
L = cellfun(@length,A);
%%extract cells of length 5
iwant = A(L==5) ;