How to convert cell array to matrix

1 回表示 (過去 30 日間)
Bashir
Bashir 2012 年 4 月 25 日
I have a cell array of size 1x16,how can I convert it to a matrix? I tried cell2mat but is always showing an error that size not consistent.Pls help asap

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 4 月 25 日
%A - data cell array
A = arrayfun(@(x)randi(10,randi(5,1,2)),1:6,'un',0);
%solution
[m,n] = cellfun(@size,A)
% horzcat
mm = max(m);
outhorz = cell2mat(arrayfun(@(x,y,z)[x{:};nan(mm - y,z)],A,m,n,'un',0))
% vertcat
nn = max(n);
outvert = cell2mat(arrayfun(@(x,y,z)[x{:},nan(y,nn - z)],A,m,n,'un',0)')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by