Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Modifying a Row Vector to Pair up Numbers

1 回表示 (過去 30 日間)
Chad
Chad 2020 年 4 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Say I have a bunch of random sequences of different lengths in a cell array:
S1 = [ 4, 6, 3, 5, 1 ], S2 = [ 3, 3, 1 ], S3 = [ 2, 4, 7, 1 ].
I want to change these to:
S1 = [ 46, 63, 35, 51 ], S2 = [ 33, 31 ], S3 = [ 24, 47, 71 ].
Any ideas?

回答 (1 件)

Tommy
Tommy 2020 年 4 月 13 日
How about this?
S1 = [ 4, 6, 3, 5, 1 ]; S2 = [ 3, 3, 1 ]; S3 = [ 2, 4, 7, 1 ];
C = {S1,S2,S3};
C2 = cellfun(@(s) 10*s(1:end-1)+s(2:end), C, 'uniform', 0);
>> C2{:}
ans =
46 63 35 51
ans =
33 31
ans =
24 47 71

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by