re-arrange data
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I apprecite yuor help for re-arranging the following data.
input (output from table out=readtable('file.xls','PreserveVariableNames',true) )
{'A'} {'B1'} {'X6(1.4M), X15(3M), X25(5M), X50(10M), X75(15M), X100(20M)'} {' X6~0, X15~1, X25~2, X50~3, X75~4, X100~5 '}
appriciated to get the following output matrix:
{'A'} {'B1'} {'X6(1.4M)'} 0
{'A'} {'B1'} {'X15(3M) '} 1
{'A'} {'B1'} {'X25(5M) '} 2
{'A'} {'B1'} {'X50(10M) '} 3
{'A'} {'B1'} {'X75(15M) '} 4
{'A'} {'B1'} {'X100(20M) '} 5
{'X6(1.4M)'} from element 3 before ccomma,
0, 1,....5 field 4 after ~
Thank you,
Br..
Joseph
0 件のコメント
採用された回答
Adam Danz
2021 年 3 月 18 日
It looks like you want the output to be a cell array.
out = {'A', 'B1', 'X6(1.4M), X15(3M), X25(5M), X50(10M), X75(15M), X100(20M)', ' X6~0, X15~1, X25~2, X50~3, X75~4, X100~5 '};
x = strtrim(strsplit(out{3},','))';
n = str2double(regexp(strtrim(strsplit(out{end},',')), '\d+$','match','once'))';
M = [repmat(out(1:2),numel(x),1), x, num2cell(n)]
Alternatively, a table,
T = table(string(repmat(out(1),numel(x),1)), ...
string(repmat(out(2),numel(x),1)),...
string(x), ...
n, 'VariableNames', {'A','B','X','n'})
15 件のコメント
その他の回答 (2 件)
David Hill
2021 年 3 月 18 日
Output will have to be a cell array.
Input= {'A','B1','X6(1.4M), X15(3M), X25(5M), X50(10M), X75(15M), X100(20M)',' X6~0, X15~1, X25~2, X50~3, X75~4, X100~5 '};
a=regexp(Input{3},'[X()0-9.M]+(?=,)','match');
b=regexp(Input{4},'(?<=~)\d+','match');
for k=1:length(a)
Output{k,1}=Input{1};
Output{k,2}=Input{2};
Output{k,3}=a{k};
Output{k,4}=b{k};
end
dpb
2021 年 3 月 18 日
編集済み: dpb
2021 年 3 月 18 日
>> C=[{'A'}, {'B1'}, {'X6(1.4M), X15(3M), X25(5M), X50(10M), X75(15M), X100(20M)'}, {' X6~0, X15~1, X25~2, X50~3, X75~4, X100~5 '} ]
C =
1×4 cell array
{'A'} {'B1'} {'X6(1.4M), X15(3M), X25(5M), X50(10M), X75…'} {' X6~0, X15~1, X25~2, X50~3, X75~4, X100~5 '}
>> split(C{3},',')
ans =
6×1 cell array
{'X6(1.4M)' }
{' X15(3M)' }
{' X25(5M)' }
{' X50(10M)' }
{' X75(15M)' }
{' X100(20M)'}
>> str2double(extractAfter(split(C{4},','),'~'))
ans =
0
1
2
3
4
5
>>
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!