How to convert cells within cells to double.

5 ビュー (過去 30 日間)
Megha
Megha 2018 年 10 月 23 日
編集済み: Bruno Luong 2018 年 10 月 23 日
How to convert cells within cells to double.
cell2mat(cell2mat(a))
does not work

回答 (3 件)

madhan ravi
madhan ravi 2018 年 10 月 23 日
編集済み: madhan ravi 2018 年 10 月 23 日
>> a=rand(1,20);
a=num2cell(a)
c=(cell2mat(a))
a =
1×20 cell array
Columns 1 through 5
{[0.5238]} {[0.5338]} {[0.8043]} {[0.0651]} {[0.5096]}
Columns 6 through 10
{[0.7079]} {[0.4156]} {[0.9226]} {[0.0987]} {[0.6105]}
Columns 11 through 15
{[0.7985]} {[0.2011]} {[0.3426]} {[0.2271]} {[0.7768]}
Columns 16 through 20
{[0.2135]} {[0.6125]} {[0.9852]} {[0.2758]} {[0.7852]}
c =
Columns 1 through 7
0.5238 0.5338 0.8043 0.0651 0.5096 0.7079 0.4156
Columns 8 through 14
0.9226 0.0987 0.6105 0.7985 0.2011 0.3426 0.2271
Columns 15 through 20
0.7768 0.2135 0.6125 0.9852 0.2758 0.7852
>>
  3 件のコメント
Megha
Megha 2018 年 10 月 23 日
Thanks @Ravi I got the answer
x = cell2mat(table2array(cell2table((x))));
madhan ravi
madhan ravi 2018 年 10 月 23 日
glad that you found

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


Andrei Bobrov
Andrei Bobrov 2018 年 10 月 23 日
Let A - your cell array with cells
out = cell2mat(cellfun(@cell2mat,A,'un',0));

Bruno Luong
Bruno Luong 2018 年 10 月 23 日
編集済み: Bruno Luong 2018 年 10 月 23 日
Just cascading CAT as many as nested level
>> c={{[1 2]} {[3 4 5]}}
c =
1×2 cell array
{1×1 cell} {1×1 cell}
>> c1=cat(2,c{:})
c1 =
1×2 cell array
{1×2 double} {1×3 double}
>> a= cat(2,c1{:})
a =
1 2 3 4 5
>>
Or doing in loop
a = c;
for level=1:2
a = cat(2,a{:});
end

カテゴリ

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