How can I convert values in a cell array into a form that can be used for calculations?

I'm sure this is a simple fix, but it's driving me crazy and I can't figure it out...
I'm using the code below in a GUI, and I need to get the data from the first row into a matrix that I can use for calculations.
data = get(handles.table, 'data');
y = data(1,:);
x = cell2mat(y);
Say I have two columns in my table, with values of 35 and 12. The cell2mat command is returning "3512" in a matrix, but what I need is "35 12". I need to be able to use the 35 and the 12 for different calculations.
Any suggestions would be much appreciated.

 採用された回答

Honglei Chen
Honglei Chen 2012 年 7 月 9 日
編集済み: Honglei Chen 2012 年 7 月 9 日
x = cellfun(@str2num,y,'UniformOutput',false)

2 件のコメント

Thank you. Now when I do that I get this error:
Error using cellfun
Non-scalar in Uniform output, at index 2, output 1.
Set 'UniformOutput' to false.
Any ideas?
Honglei Chen
Honglei Chen 2012 年 7 月 9 日
I updated the answer. It is probably because not all of your numbers have the same number of digits.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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