Can i delete part of a cell array based on a condition?

1 回表示 (過去 30 日間)
Damien Williams
Damien Williams 2019 年 5 月 8 日
コメント済み: Damien Williams 2019 年 5 月 8 日
if i have a cell array such as {'CGU'} {'UUU'} {'UAG'} {'GGU'} can i
identify if there is a member of {'UAA','UAG','UGA'} and delete the
remaining elements? eg, leaving {'CGU'} {'UUU'} once {'UAG'} is identified.

採用された回答

James Tursa
James Tursa 2019 年 5 月 8 日
編集済み: James Tursa 2019 年 5 月 8 日
E.g.,
>> C = {'CGU','UUU','UAG','GGU'}
C =
1×4 cell array
{'CGU'} {'UUU'} {'UAG'} {'GGU'}
>> X = {'UAA','UAG','UGA'}
X =
1×3 cell array
{'UAA'} {'UAG'} {'UGA'}
>> f = find(ismember(C,X),1)
f =
3
>> C(f+1:end) = []
C =
1×3 cell array
{'CGU'} {'UUU'} {'UAG'}
  1 件のコメント
Damien Williams
Damien Williams 2019 年 5 月 8 日
I wanted to remove the index element also, so i excluded the +1 and everything seems great.
Thankyou.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by