フィルターのクリア

Turning numbers from string into doubles / into table with doubles

3 ビュー (過去 30 日間)
Christian Schumacher
Christian Schumacher 2019 年 1 月 10 日
回答済み: madhan ravi 2019 年 1 月 10 日
Hello,
I have a database which I am trying to convert into Matlab as a table. This generally works really well, but now I am having a problem, which I wasn't able to solve with the Internet.
The database gives me a column with date like this: [21, 22, 34,36]. When I try to convert this via excel-import, as i have done it before, it is only convertable as a string. Doing this, I tried to turn the string arry into cells or doubles with stringsplit or string2double. Both was unsuccessful.
With the function erase, i was able to erase "[" and "]", so i have still "21,22,34,36" left. With the options i mentioned above I am still not able to convert the string to double, the data must be something like this, to use string2double: " '21', '22','34','36' ".
Has anyone an idea?
Thank you for your help,
Kind regards
Christian

採用された回答

Stephen23
Stephen23 2019 年 1 月 10 日
>> S = '[21, 22, 34,36]';
>> V = sscanf(S(2:end),'%f,')
V =
21
22
34
36

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 1 月 10 日
a=" '21', '22','34','36' ";
b=strsplit(strrep(a,'''',''),',');
Result=str2double(b)
Gives:
Result =
21 22 34 36

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by