Converting Table Output from 1 Format to Another

2 次查看(过去 30 天)
Hi I have the following output from a table my question is:
Which format is the best to manipulate the data ie Double/String etc and how to convert it to the new data, preferably Double?
Note this is not the width of the table but forms part of a 45 column table with the majority of data as Double.
A =
17×2 table
NNODSC Product Code
___________ _______________
16 {'28/0.85'} {'XHHP15AA001'}
25 {'43/0.85'} {'XHHP17AA001'}
35 {'24/1.35'} {'XHHP18AA001'}
50 {'34/1.35'} {'XHHP19AA001'}
70 {'30/1.7' } {'XHHP20AA001'}
95 {'30/1.7' } {'XHHP22AA001'}
120 {'48/1.35'} {'XHHP23AA001'}
150 {'48/1.35'} {'XHHP24AA001'}
185 {'48/1.35'} {'XHHP25AA001'}
240 {'48/1.35'} {'XHHP26AA001'}
300 {'48/1.35'} {'XHHP27AA001'}
400 {'48/1.35'} {'XHHP28AA001'}
500 {'48/1.35'} {'XHHP30AA001'}
630 {'48/1.35'} {'XHHP32AA001'}
800 {'48/1.35'} {'XHHP33AA001'}
1000 {'48/1.35'} {'XHHP34AA001'}
1200 {'48/1.35'} {'XHHP50AA001'}
Any advice will be helpful.
Thanks.
  3 个评论
Walter Roberson
Walter Roberson 2023-2-16
Do you need to convert '28/0.85' to numeric 28 divided by 0.85, and so on?
Frank Lehmann
Frank Lehmann 2023-2-16
Walter,
No, I just want the expression as an example 48/1.35 is what I want, not 35.555 as the result of a divisible number?
I would just to be able to manipulate the data in whatever format is appropriate?
Cheers,
Frank

请先登录,再进行评论。

回答(1 个)

Stephen23
Stephen23 2023-2-16
编辑:Stephen23 2023-2-16
T = cell2table({'28/0.85','XHHP15AA001';'43/0.85','XHHP17AA001';'24/1.35','XHHP18AA001';'34/1.35','XHHP19AA001'},...
'VariableNames',{'NNODSC','Product Code'},'RowNames',{'16','25','35','50'})
T = 4×2 table
NNODSC Product Code ___________ _______________ 16 {'28/0.85'} {'XHHP15AA001'} 25 {'43/0.85'} {'XHHP17AA001'} 35 {'24/1.35'} {'XHHP18AA001'} 50 {'34/1.35'} {'XHHP19AA001'}
F = @(C)double(split(string(C),'/'));
T = convertvars(T,'NNODSC',F)
T = 4×2 table
NNODSC Product Code __________ _______________ 16 28 0.85 {'XHHP15AA001'} 25 43 0.85 {'XHHP17AA001'} 35 24 1.35 {'XHHP18AA001'} 50 34 1.35 {'XHHP19AA001'}
T = splitvars(T,'NNODSC','NewVariableNames',{'NNODSC_L','NNODSC_R'}) % optional
T = 4×3 table
NNODSC_L NNODSC_R Product Code ________ ________ _______________ 16 28 0.85 {'XHHP15AA001'} 25 43 0.85 {'XHHP17AA001'} 35 24 1.35 {'XHHP18AA001'} 50 34 1.35 {'XHHP19AA001'}

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by