フィルターのクリア

How do I split double-digit elements in a vector into two separate elements?

2 ビュー (過去 30 日間)
Jakob Siegel
Jakob Siegel 2016 年 11 月 28 日
編集済み: Andrei Bobrov 2016 年 11 月 28 日
I have a vector, v = [1 18 9 8], and I'm trying to split up the 18 into two separate elements so that the new vector would be new_vec = [1 1 8 9 8]. Any ideas on how to approach this?

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2016 年 11 月 28 日
編集済み: Andrei Bobrov 2016 年 11 月 28 日
v = [1 18 9 8];
new_vec = sprintf('%d',v)-'0';

bio lim
bio lim 2016 年 11 月 28 日
編集済み: bio lim 2016 年 11 月 28 日
Simple approach would be:
v = [1 18 9 8];
for i = 1 : length(v)
new_vec{i} = num2str(v(i)) - '0'
end
new_vec = cell2mat(new_vec);
The output is:
new_vec =
1 1 8 9 8

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by