How to convert string to double array in table

27 ビュー (過去 30 日間)
rampavan medi
rampavan medi 2021 年 9 月 24 日
コメント済み: rampavan medi 2021 年 9 月 24 日
I have a table with string of values in columns.
T1 =
5×1 table
A
___________________________________________________________________________________
{'[28.346853874154966, 284.04836936606813, 57.820072802912115, 64.72700622938805]'}
{'[16.520020800832032, 120.07328691828508, 57.82007280291212, 46.34078417002567]' }
{0×0 char }
{0×0 char }
{0×0 char }
When i am using this code T1.(1) = str2double(T1{:,1}); I am getting NaN values. in table.
T1 =
5×1 table
A
________
NaN
NaN
NaN
NaN
NaN
I am expecting follwing output
T1 =
5×1 table
A
___________________________________________________________________________________
[28.346853874154966, 284.04836936606813, 57.820072802912115, 64.72700622938805]
[16.520020800832032, 120.07328691828508, 57.82007280291212, 46.34078417002567]
[]
[]
[]
How to code this?
  1 件のコメント
the cyclist
the cyclist 2021 年 9 月 24 日
It would be easier for us to make sure suggested code works as you expect if you uploaded the table T1 in a *.mat file, using the paperclip icon in the INSERT section of the toolbar.

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

採用された回答

the cyclist
the cyclist 2021 年 9 月 24 日
% My best guess at your data
A = {'[28.346853874154966, 284.04836936606813, 57.820072802912115, 64.72700622938805]';
'[16.520020800832032, 120.07328691828508, 57.82007280291212, 46.34078417002567]';
'';
'';
''};
T1 = table(A);
% Convert to a cell array of doubles
M = cellfun(@str2num,T1.A,'UniformOutput',false)
  1 件のコメント
rampavan medi
rampavan medi 2021 年 9 月 24 日
Thanks you so much

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

その他の回答 (0 件)

カテゴリ

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