Splitting the elements in the cell array

57 ビュー (過去 30 日間)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2016 年 10 月 28 日
編集済み: Gopalakrishnan venkatesan 2018 年 12 月 18 日
I have a cell array,
a = { abcdsfa_def , ef_ghi, higdsfasfa_klm}
Now i need to remove the each element in the cell array from '_'.
my answer should be a = {abcdsfa, ef, higdsfasfa}
Thanks a lot
  1 件のコメント
Jan
Jan 2016 年 10 月 28 日
編集済み: Jan 2016 年 10 月 28 日
Why does splitting 'abcdsfa_def' at '_' yield 'abc'? I'd expect 'abcdsfa'. 'efg' looks even more strange.

サインインしてコメントする。

採用された回答

Jan
Jan 2016 年 10 月 28 日
While this does not match the shown output, it matches your explanations:
a = {'abcdsfa_def', 'ef_ghi', 'higdsfasfa_klm'}
r = strtok(a, '_')

その他の回答 (1 件)

KSSV
KSSV 2016 年 10 月 28 日
a = { 'abc_def' , 'efg_ghi', 'hig_klm'}
b = cellfun(@(x) x(1:3), a, 'UniformOutput', false)
  2 件のコメント
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2016 年 10 月 28 日
Number of elements before underscore is not all alway three, a = {abcdef_dasf, as_dfafdsa} What to do in this case ?
KSSV
KSSV 2016 年 10 月 28 日
a = {'abcdef_dasf', 'as_dfafdsa'} ;
b = cell(size(a)) ;
for i= 1:length(a)
t = strsplit(a{i},'_') ;
b{i} = t{1} ;
end
b

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by