trimming matrix arrays arranged within cell arrays
조회 수: 7 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
madhan ravi
2020년 7월 8일
TrimmedArray = cellfun(@(x) x(1:10,:),CellArray,'un',0);
celldisp(TrimmedArray)
댓글 수: 0
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!