필터 지우기
필터 지우기

Accessing cell array data every 2 columns and concatenating them

조회 수: 3 (최근 30일)
ErikaZ
ErikaZ 2018년 6월 27일
답변: Rik 2018년 6월 27일
I have cell array A =
{1×137 cell} {1×134 cell} {1×410 cell} {1×411 cell} {1×439 cell} {1×455 cell}
{1×137 cell} {1×134 cell} {1×410 cell} {1×411 cell} {1×439 cell} {1×455 cell}
{1×137 cell} {1×134 cell} {1×410 cell} {1×411 cell} {1×439 cell} {1×455 cell}
I need to concatenate columns 1 & 2 and 3 & 4 and 5 & 6, so cell array A is 3x3
{1×271 cell} {1×821 cell} {1×894 cell}
{1×271 cell} {1×821 cell} {1×894 cell}
{1×271 cell} {1×821 cell} {1×894 cell}
The column size within A is not always the same size.
Thank you,

채택된 답변

Rik
Rik 2018년 6월 27일
Easy with cellfun:
%generate random data:
A=cell(3,6);x=[137 134 410 411 439 455];
for r=1:size(A,1)
for c=1:size(A,2)
A{r,c}=num2cell(randi(10,1,x(c)));
end
end
%the actual line of code:
A=cellfun(@(x1,x2) [x1,x2],A(:,1:2:end),A(:,2:2:end),'UniformOutput',0);

추가 답변 (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