A very quick question
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
2 Kommentare
Antworten (2)
David J. Mack
am 12 Apr. 2017
Bearbeitet: David J. Mack
am 12 Apr. 2017
Hey Radoslav,
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'}))
str = '1 0 0 1';
idb = strfind('1',str(~isspace(str))); % Remove spaces
Hope that helps.
Greetings, David
0 Kommentare
Andrei Bobrov
am 12 Apr. 2017
Bearbeitet: Andrei Bobrov
am 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);
2 Kommentare
Siehe auch
Kategorien
Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!