MATLAB Answers

Comparing and locating string values

1 view (last 30 days)
Jose Grimaldo
Jose Grimaldo on 16 Feb 2020
Edited: Stephen Cobeldick on 16 Feb 2020
I have a x=1x10 string of colors and the user enters a a=1x3 string of colors. Im trying to get the index of the location in the x-variable. How can i achieve that?
% my code
% User input
% I try this but it does not work
  1 Comment
Walter Roberson
Walter Roberson on 16 Feb 2020
Look at the second output of ismember()

Sign in to comment.

Accepted Answer

stozaki on 16 Feb 2020
Edited: stozaki on 16 Feb 2020
Please try following command.
ret = find(ismember(x,a))
  1 Comment
Stephen Cobeldick
Stephen Cobeldick on 16 Feb 2020
Simpler and more efficient without the superfluous find:
>> [~,idx] = ismember(a,x)
idx =
1 3

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!