필터 지우기
필터 지우기

group every ten cell array

조회 수: 4 (최근 30일)
pasta pontikaki
pasta pontikaki 2019년 5월 18일
편집: pasta pontikaki 2019년 5월 20일
Hi all i have a cell array 1x180 and i want to group by every 10 cells
conc.PNG
For example i want the elements from 1 cell till 10 get grouped,11:21, 22:32 etc..
So the new cell should be 1x18
How can i do this?

채택된 답변

Adam Danz
Adam Danz 2019년 5월 18일
편집: Adam Danz 2019년 5월 18일
c = cell(1,180); % the original 1x180 cell array
newCell = mat2cell(c,1,repmat(10,1,18)); %the new nested cell array
  댓글 수: 5
Adam Danz
Adam Danz 2019년 5월 19일
편집: Adam Danz 2019년 5월 19일
Yeah, you can still concatenate them vertically but you'd need to pad the shorter vectors. Here are both methods:
Concatenate horizontally
newCellMerge = cellfun(@(x)[x{:}],newCell, 'UniformOutput', false);
Concatenate vertically, pad with NaN values at the end of short vectors
newCellMerge = cell(size(newCell));
for i = 1:length(newCell)
len = cellfun(@length, newCell{i});
cellPad = cellfun(@(x,y)padarray(x',y,NaN,'post')',newCell{i}, num2cell(max(len)-len),'UniformOutput',false)';
newCellMerge{i} = cell2mat(cellPad);
end
pasta pontikaki
pasta pontikaki 2019년 5월 20일
편집: pasta pontikaki 2019년 5월 20일
please sir with all duly respect could you please answer in this question if you know
I will realy appreciate this it is a matter of life or death for my homework

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by