Clear Filters
Clear Filters

find element egual to substring in array string

1 view (last 30 days)
c=["A1_asd";"A2_rrd";"A_dj";"B1_gre";"B2_rffe";"B3_rffe"]
c = 6×1 string array
"A1_asd" "A2_rrd" "A_dj" "B1_gre" "B2_rffe" "B3_rffe"
%i want to catch string before letter_ and search member
%find all member egual to A in c;
%find all member egual to B in c;
result:
["A1_asd";"A2_rrd";"A_dj"]
["B1_gre";"B2_rffe";"B3_rffe"]

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 21 Nov 2023
From what I understood of the given information -
%Input
c=["A1_asd";"A2_rrd";"A_dj";"B1_gre";"B2_rffe";"B3_rffe"]
c = 6×1 string array
"A1_asd" "A2_rrd" "A_dj" "B1_gre" "B2_rffe" "B3_rffe"
%Output
a = c(startsWith(c, 'A'))
a = 3×1 string array
"A1_asd" "A2_rrd" "A_dj"
b = c(startsWith(c, 'B'))
b = 3×1 string array
"B1_gre" "B2_rffe" "B3_rffe"

More Answers (0)

Community Treasure Hunt

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

Start Hunting!