Accessing cell array data every 2 columns and concatenating them

1 次查看(过去 30 天)
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 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by