Concatenate cell array inside a cell array

조회 수: 11 (최근 30일)
suman Dhamala
suman Dhamala 2018년 2월 23일
답변: Voss 2023년 9월 24일
My cell array is of different size. I want to convert it to the matrix. I added NAN to make the size equal but I found NAN added inside a cell array like the picture [1*481]. I try to horzcat it but did not work. Can anyone help me, please?

답변 (1개)

Voss
Voss 2023년 9월 24일
C = {rand(1,7),rand(1,4),rand(1,3)};
disp(C);
{[0.9714 0.8038 0.7325 0.4787 0.1328 0.8788 0.6320]} {[0.1632 0.6340 0.3939 0.5810]} {[0.8846 0.5465 0.3481]}
num = cellfun(@numel,C);
N = numel(C);
M = NaN(N,max(num));
for ii = 1:N
M(ii,1:num(ii)) = C{ii};
end
disp(M);
0.9714 0.8038 0.7325 0.4787 0.1328 0.8788 0.6320 0.1632 0.6340 0.3939 0.5810 NaN NaN NaN 0.8846 0.5465 0.3481 NaN NaN NaN NaN

카테고리

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