How do I convert a cell array of structures into a numeric array?

I have a cell array (1xN cell) from a database query, in which each element is a structure with a single field. That field is a string, but the strings always contain numbers. I want to convert this cell array into a numeric array. Although I could easily do it with a for loop, it seems that there should be a way to convert directly without using loops. None of the conversion commands work for this particular type of cell array and I haven't found an approach that works anywhere else.
In case it helps, this shows what I'm dealing with:
x{1}.Text = '100'; x{2}.Text = '200';
I want to use some conversion of this to another variable y so that
>> y
y =
100 200
Thanks for your help

 採用された回答

ES
ES 2017 年 3 月 21 日
編集済み: ES 2017 年 3 月 21 日

1 投票

temp = cell2mat(x);
temp = {temp.Text}
y = cellfun(@str2num, temp)

1 件のコメント

Erik Larsen
Erik Larsen 2017 年 3 月 21 日
編集済み: Erik Larsen 2017 年 3 月 21 日
This is great, thanks for the help!

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2017 年 3 月 21 日

編集済み:

2017 年 3 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by