Filter löschen
Filter löschen

Accessing cell array data every 2 columns and concatenating them

2 Ansichten (letzte 30 Tage)
ErikaZ
ErikaZ am 27 Jun. 2018
Beantwortet: Rik am 27 Jun. 2018
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,

Akzeptierte Antwort

Rik
Rik am 27 Jun. 2018
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);

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by