I need to look for entries in different strings

Hello,
I am trying to use strcmp for more than one input string to check one entry in all the inputs. For example
M1=[1 2 3];
M2=[2 3 4];
M3=[3 4 5];
M4=[1 3 5];
If I have a long string of St=[1 2 3 4 5 6 7];
I need some sort of a command or a way that checks str(1) in M1,M2,M3,M4 and returns 1001
Thank You

Answers (1)

dpb
dpb on 31 Mar 2015
Edited: dpb on 1 Apr 2015
>> ~cellfun(@isempty,strfind({M1;M2;M3;M4},'1'))
ans =
1
0
0
1
>>
ADDENDUM
If it's wanted a string result, then simply cast
>> num2str(~cellfun(@isempty,strfind({M1;M2;M3;M4},'1')).','%1d')
ans =
1001
>>
NB: Must convert each M to a string first from your numeric representation. Or, of course, you can search as numeric for integers
>> any(ismember([M1;M2;M3;M4],1),2)
ans =
1
0
0
1
>>

This question is closed.

Asked:

on 31 Mar 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!