How to combine numeric contents inside a cell array with another numeric matrix

I want to combine numeric contents inside a cell array with another numeric matrix. The following is a simple demo code.
%%generate a cell array with numeric contents
k=1;
for i=1:3
for j=1:4
RowCol{k}=[i j];
k=k+1;
end
end
%%another numeric matrix, contents can be NaN or numeric
XY=NaN(numberrow*numbercolumn,2);
%%Combine numeric contents inside a cell array with another numeric matrix
for ii=1:12
Data(ii)=[RowCol{ii,1},XY(ii,:)]
end
The combination doesn't work! Could you please help me out? Anyone has any suggestions? I highly appreciate it.

 採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 11 日
Data{ii} = [RowCol{ii,1},XY(ii,:)]
Notice change of (ii) to {ii}
In place of your loop you could use
Data = cellfun(@(A,B) [A,B], RowCol, XY, 'Uniform', 0);

1 件のコメント

Jiali
Jiali 2015 年 6 月 14 日
Wonderful! Thank you for sharing "Cellfun" function, really useful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

質問済み:

2015 年 6 月 11 日

コメント済み:

2015 年 6 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by