フィルターのクリア

Accessing cell array data every 2 columns and concatenating them

1 回表示 (過去 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 Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by