How can i split between strings that connected with under score?

22 ビュー (過去 30 日間)
ben velt
ben velt 2015 年 5 月 23 日
回答済み: Walter Roberson 2015 年 5 月 23 日

" x= 'Penelope_Cruz' 'Gary_Cooper' 'Tony_Curtis' 'Jim_Carrey'"

I want to split x into two different variables, like this:

a= 'Penelope' 'Gary' 'Tony' 'Jim'

b= 'Cruz' 'Cooper' 'Curtis' 'Carrey'

I want to do it for unknown amount of names.

採用された回答

pietro
pietro 2015 年 5 月 23 日
編集済み: pietro 2015 年 5 月 23 日
one solution:
x={ 'Penelope_Cruz' 'Gary_Cooper' 'Tony_Curtis' 'Jim_Carrey'};
for i=1:length(x)
temp=strsplit(x{i},'_');
a(i)=temp(1);
b(i)=temp(2);
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 5 月 23 日
T = regexp(x, '_', 'split');
a = cellfun(@(C) C{1}, T);
b = cellfun(@(C) C{2}, T);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by