trimming matrix arrays arranged within cell arrays

7 views (last 30 days)
I have a cell array (CellArray) where wihtin each cell is a matrix of multiple collumns and rows of numbers.
To call each the first array of numbers, I simply write: CellArray{1}, the second CellArray{2}.
I would like to use cellfun to trim the column lengths of each array in each cell so they are all the same number of rows (for example 10 rows).
I know it should look something like this, but I don't know how to correctly define the function without involving a for-loop:
TrimmedArray = CellArray((cellfun(@CellArray{:,1:10})));
I would love some suggestions for how to implement the cellfun function better.
Until then, I am going to make do with a long and ugly for loop.

Answers (2)

madhan ravi
madhan ravi on 8 Jul 2020
TrimmedArray = cellfun(@(x) x(1:10,:),CellArray,'un',0);
celldisp(TrimmedArray)

James Tursa
James Tursa on 8 Jul 2020
It is not clear whether you want the rows or columns trimmed. Maybe one of these is what you want?
TrimmedArray = cellfun(@(x) x(:,1:10),CellArray,'uni',false);
or
TrimmedArray = cellfun(@(x) x(1:10,:),CellArray,'uni',false);

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!