trimming matrix arrays arranged within cell arrays

8 visualizaciones (últimos 30 días)
Kathryn Feller
Kathryn Feller el 8 de Jul. de 2020
Respondida: James Tursa el 8 de Jul. de 2020
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.

Respuestas (2)

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

James Tursa
James Tursa el 8 de Jul. de 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);

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by