converting only certain cells to a matrix

consider the following example
a = { rand(1877958,7); rand(1251972,7); rand(4564357,7) };
i want only the first two cells to be converted to a matrix. i know that the rows are not the same but the remaining rows can be filled with zeros. how can i do that in such a way so that the output has 14 columns meaning the matrices are put adjacent to each other. thanks

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 29 日
編集済み: Azzi Abdelmalek 2014 年 11 月 29 日

2 投票

a = { rand(1877958,7); rand(1251972,7); rand(4564357,7) };
n=max(cellfun(@(x) size(x,1) , a(1:2)) )
b=cell2mat(cellfun(@(x) [x;zeros(n-size(x,1),7)],a(1:2)','un',0));

6 件のコメント

AA
AA 2014 年 11 月 29 日
Is there a way to do this conversion without the zeros?
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 29 日
How? you must get the same number of rows if you want to concatenate them horizontally
AA
AA 2014 年 11 月 29 日
You are right. Your formula concentrates them vertically. How can i concentrate the tables horizontally so that i get 14 columns. Thanks
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 29 日
No, they are horizontally concatenated, look at the size, it's 1877958x14
AA
AA 2014 年 11 月 29 日
I apologize. You r right. How would I vertically arrange the tables without zeros and 7 columns. Thanks
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 29 日
This is easier
b=cell2mat(a(1:2));

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

AA
2014 年 11 月 29 日

コメント済み:

2014 年 11 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by