Converting Table Output from 1 Format to Another

조회 수: 2 (최근 30일)
Frank Lehmann
Frank Lehmann 2023년 2월 16일
편집: Stephen23 2023년 2월 16일
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