cell配列内のstring配列を文字数で分割して、新たなcell配列を作る方法を教えてください。
4 views (last 30 days)
Show older comments
下記のような10×1のcell配列 cがあります。
cの各要素は16文字で、これを8文字ずつ分割し、
10×2のcell配列 dを作る方法を教えていただきたいです。
よろしくお願いいたします。
a = randn(1,10);
T = numerictype(true,64,60);
F = fimath('OverflowMode', 'saturate',...
'RoundMode', 'round',...
'SumMode', 'FullPrecision',...
'ProductMode', 'FullPrecision',...
'MaxProductWordLength', 256,...
'MaxSumWordLength', 256);
a_fi = fi(a,T,F);
b_fi = hex(a_fi);
c = strsplit(b_fi)'
0 Comments
Accepted Answer
Hernia Baby
on 21 Jul 2022
a = randn(1,10);
T = numerictype(true,64,60);
F = fimath('OverflowMode', 'saturate',...
'RoundMode', 'round',...
'SumMode', 'FullPrecision',...
'ProductMode', 'FullPrecision',...
'MaxProductWordLength', 256,...
'MaxSumWordLength', 256);
a_fi = fi(a,T,F);
b_fi = hex(a_fi);
c = strsplit(b_fi)'
% 1~8文字だけ抜き出す
c1 = cellfun(@(x) x(1:8),c,'UniformOutput',false)
% 9~最後まで抜き出す
c2 = cellfun(@(x) x(8:end),c,'UniformOutput',false)
% 2つのcellを結合
c3 = [c1, c2]
3 Comments
Akira Agata
on 26 Jul 2022
この問題、私もcody脳が疼きました。
以下のような方法ではどうでしょう?
c = {'0c23f10982cb9580';'1acea553c2c99c00'}; % 2行コピーしました
c2 = regexprep(c,'(^\w{8})(\w{8}$)','$1,$2'); % 最初の8文字と最後の8文字の間にカンマを入れる
e = split(c2,',') % カンマでスプリット
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!