How to convert cell to matrix

I have a cell which is given by A= 1x13cell. I want to extract the contents of the cell into the form of a matrix of size (13 x number of points each cell containd) is this possible? The number of points in each cell varies. Can you help me with this?

2 件のコメント

Jos (10584)
Jos (10584) 2013 年 7 月 16 日
I suggest you give a small example. For instance, if
C = {[1 2],[11 12 13]} % a cell array
how would you like the final matrix M to look like? Something like
1 2 NaN
11 12 13
?
Ede gerlderlands
Ede gerlderlands 2013 年 7 月 16 日
yes, that's what I need

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

回答 (3 件)

Jan
Jan 2013 年 7 月 16 日
編集済み: Jan 2013 年 7 月 16 日

2 投票

N = cellfun('length', C);
M = numel(C);
R = NaN(M, N);
for k = 1:M
R(1:N(k)) = C{k}; % Perhaps: reshape(C{k}, 1, [])
end

1 件のコメント

Ede gerlderlands
Ede gerlderlands 2013 年 7 月 16 日
編集済み: Ede gerlderlands 2013 年 7 月 16 日
Thank you for yor reply. But this gives me the whole nubers that are found in the cell in the decending order following rows. What I really want is the numbers per cell . That is 13 rows and what is found in them . Thank you

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

David (degtusmc)
David (degtusmc) 2013 年 7 月 16 日
編集済み: David (degtusmc) 2013 年 7 月 16 日

2 投票

Look up cell2mat. The link for the documentation is below. I hope this helps

3 件のコメント

Ede gerlderlands
Ede gerlderlands 2013 年 7 月 16 日
I tried but didn't help me
Evan
Evan 2013 年 7 月 16 日
This will only work for cells arrays containing matrices of constant size in each array.
David (degtusmc)
David (degtusmc) 2013 年 7 月 18 日
That is true. I did not think about that. Thank you Evan.

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

Jos (10584)
Jos (10584) 2013 年 7 月 17 日
編集済み: Jos (10584) 2013 年 7 月 17 日

1 投票

Here is a suggestion
C = {[1 2 ;3 4],[11 12 13].',100:106} % a cell array
% make sure all elements are column vectors
C2 = cellfun(@(x) reshape(x,[],1), C,'un',0) ;
M = padcat(C2{:})

1 件のコメント

Tehmina Kakar
Tehmina Kakar 2018 年 7 月 18 日
Thank you so much @Jos. It works for me.

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

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

質問済み:

2013 年 7 月 16 日

コメント済み:

2018 年 7 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by