필터 지우기
필터 지우기

How to convert a cell array of different size to matrix of fixed size

조회 수: 4 (최근 30일)
Anupam  Saikia
Anupam Saikia 2018년 10월 9일
댓글: Anupam Saikia 2018년 10월 10일
I have a cell array A of dimension 1x22 each cell having different number of elements with compulsory 2 columns. for example A{1,1}= [ 23 34; 44 55; 56 71; 63 49; 71 30]
A{1,2}= [12 13; 10 99] and so on. Now, I need a matrix which has maximum number of columns equal to 44(twice the number of cell array columns) and rows equal to the maximum number of columns of all the cells. Here, it is 5(from A{1,1}) NaN or 0 values do not matter in my case.

채택된 답변

Jan
Jan 2018년 10월 9일
편집: Jan 2018년 10월 9일
nCol = cellfun('size', A, 1);
nRow = numel(A) * 2;
Output = NaN(max(nCol), nRow);
But I guess you want to insert the values of the cell also. Then:
for iA = 1:numel(A)
idx = (iA - 1) * 2 + 1;
Output(1:nCol(iA), idx:idx+1) = A{iA};
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by