I have a 1x6 array X = {‘a’,’b’,’​c’,’d’,’e’​,’f’}. I want a command that returns the element of X that contains a particular string. E.g. a command that if I tell it to find ‘d

1 view (last 30 days)
asking for a friend

Answers (1)

Torsten
Torsten on 16 Sep 2022
Edited: Torsten on 16 Sep 2022
str = ["asdfsd","bfgfd","cyf","ddfhf","effdg","dgdgdf"];
pat = "d";
[~,i] = find(contains(str,pat)==1)
i = 1×5
1 2 4 5 6

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!