trimming matrix arrays arranged within cell arrays

7 ビュー (過去 30 日間)
Kathryn Feller
Kathryn Feller 2020 年 7 月 8 日
回答済み: James Tursa 2020 年 7 月 8 日
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.

回答 (2 件)

madhan ravi
madhan ravi 2020 年 7 月 8 日
TrimmedArray = cellfun(@(x) x(1:10,:),CellArray,'un',0);
celldisp(TrimmedArray)

James Tursa
James Tursa 2020 年 7 月 8 日
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);

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by