필터 지우기
필터 지우기

equalizing few matrices size in a cell

조회 수: 3 (최근 30일)
khaled alsaih
khaled alsaih 2021년 5월 4일
댓글: KSSV 2021년 5월 4일
Hello everyone, and thanks in advance
let's say I have a cell of 10 arrays. but the arrays are not having the same dimensions.
example: 60000x1 , 65478x1, 74578x1 and so on. how can i make all the arrays the same size, knowing that i want the dimensions to have the least size so no zeros padding.
thanks a lot

채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 4일
minlen = min(cellfun(@length, YourCell));
truncCell = cellfun(@(C) C(1:minlen), YourCell, 'uniform', 0)

추가 답변 (1개)

KSSV
KSSV 2021년 5월 4일
% demo data
C{1} = rand(60000,1) ;
C{2} = rand(65478,1) ;
C{3} = rand(74578,1) ;
% lengths of each cell array
L = cellfun(@length,C) ;
% do interpolation to get the cell array to same size
for i = 1:length(C)
C{i} = interp1((1:L(i))',C{i},linspace(1,L(i),min(L))) ;
end
  댓글 수: 2
khaled alsaih
khaled alsaih 2021년 5월 4일
i have 10 cells and sometimes more, is there any dynamic way to accept any number of arrays and reduce them to the smallest matrix size?
KSSV
KSSV 2021년 5월 4일
The above code works for any given cell array C of any size .

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by