## A very quick question

on 12 Apr 2017
Latest activity Commented on by Radoslav Gagov

on 12 Apr 2017
Hello Guys. Can you tell me how can I write a code that is like
>> [ida,idb] = ismember('1','1 0 0 1')
ida =
logical
1
idb =
1
but the outpoot i need is
idb =
[1 4]
I suppose it can be made with a double loop or smth, but I am looking for a simpler way.

Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 12 Apr 2017
@Radoslav Gagov: do the inputs have to be strings ? Or can they be numeric?

on 12 Apr 2017
Normally they are numeric or logical

### David J. Mack (view profile)

on 12 Apr 2017
Edited by David J. Mack

### David J. Mack (view profile)

on 12 Apr 2017

In general, to convert a logical array to ids use find.
If you are working on numbers (as implied in your example) try
idb = find(ismember(1,[1 0 0 1])) % No quotes!
If you work on strings, either use a "set" with a cellstr:
idb = find(ismember('1',{'1','0','0','1'}))
Or better, use strfind without the spaces.
str = '1 0 0 1';
idb = strfind('1',str(~isspace(str))); % Remove spaces
Hope that helps.
Greetings, David

### Andrei Bobrov (view profile)

on 12 Apr 2017
Edited by Andrei Bobrov

### Andrei Bobrov (view profile)

on 12 Apr 2017

A = '1 0 0 1';
B = '1';
An = A - '0';
Bn = B - '0';
An = An(An >= 0);
Bn = Bn(Bn >= 0);
idb = find(Bn == An);
for numeric
idb = find(B == A);