How to convert cell to double array?

1,192 ビュー (過去 30 日間)
Gil Cheah
Gil Cheah 2017 年 7 月 19 日
回答済み: Philipp Prestel 2023 年 6 月 24 日
My data is with size of 2050x1 and its class label as 'cell', how do convert it into double so that i can plot the graph? thanks for the help in advance

採用された回答

Geoff Hayes
Geoff Hayes 2017 年 7 月 19 日
Gil - is each element of your cell array a numeric scalar or numeric array? See cell2mat which provides some examples on how you might do this conversion.

その他の回答 (2 件)

Damdae
Damdae 2019 年 7 月 27 日
Try str2double:
cell2mat({'01'}) = '01' (double)
str2double({'01'}) = 1 (char)
  1 件のコメント
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco 2021 年 11 月 29 日
Thanks Damdae, very useful tip to convert
cell array, containg numbers, to double.
Best.

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


Philipp Prestel
Philipp Prestel 2023 年 6 月 24 日
The absolute easiest way I know is comma seperated list assignment, which looks like this;
a = [{25}; {31}; {24}; {5}; {23}; {64}; {12}; {53}; {22}];
b = [a{:}]'
b = 9×1
25 31 24 5 23 64 12 53 22
I don't know whrether it is any good, but it works if the values of all cells are of the same type. just keep in mind that it will transpose a columnvector to a rowvector.

カテゴリ

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