필터 지우기
필터 지우기

How to avoid cell2mat while reshaping cell arrays

조회 수: 1 (최근 30일)
wave_buoys
wave_buoys 2019년 5월 2일
댓글: wave_buoys 2019년 5월 2일
Hi,
I have 1 x 2 cell: 55430 x 2350 and 55430 x 2200 elements
Try to avoid using cell2mat, is there any another way to reshape this 1x2 cell to get: 1 x 55430 cell: 1 x 4550 elements (4550 = 2350 + 2200);
Thank you

채택된 답변

Stephen23
Stephen23 2019년 5월 2일
편집: Stephen23 2019년 5월 2일
Simple way using concatenation:
C = {rand(55430,2350),rand(55430,2200)}; % fake data
D = num2cell(horzcat(C{:}),2);
But I guess you are trying to avoid some "out of memory" errors, in which case loops might help:
N = numel(C);
R = size(C{1},1);
D = cell(1,R);
for ii = 1:R
T = cell(1,N);
for jj = 1:N
T{jj} = C{jj}(ii,:);
end
D{ii} = [T{:}];
end
Giving:
>> size(D)
ans =
1 55430
>> size(D{1})
ans =
1 4550
>> size(D{end})
ans =
1 4550
  댓글 수: 1
wave_buoys
wave_buoys 2019년 5월 2일
Wonderful ! This is what I want! Indeed, I try to avoid cell2mat that is related to "out of memory" errors
Thank you so much!

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

추가 답변 (1개)

KSSV
KSSV 2019년 5월 2일
C{1} = rand(55430,2350) ;
C{2} = rand(55430,2200) ;
C1 = num2cell([C{1}(:,1) C{2}(:,1)],2) ;
C2 = num2cell([C{1}(:,2:end) C{2}(:,2:end)],2) ;
  댓글 수: 1
Stephen23
Stephen23 2019년 5월 2일
wave_buoys's "Answer" moved here:
Hi, thanks for a quick answer,
this could a solution, but I was expecting a better approach via 'for' loop, so that I can apply for 1 x n cell.
Could you?

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by