MATLAB Answers

Locating entered vector values

1 view (last 30 days)
I have a vector x=(0:1:9) and the user has to input a vector (single integers). How can i locate the values the user input in the x variable? Can it be done without using loops?
x=[0 1 2 3 4 5 6 7 8 9];
% User input vector
a=[1 4 0 0];
% I was trying this but it fails when i run the code
>> [r,c]=find(ColorNum(rst(1:end)));

  0 Comments

Sign in to comment.

Accepted Answer

Bhaskar R
Bhaskar R on 16 Feb 2020
ind = find(ismember(x, a))

  1 Comment

Stephen Cobeldick
Stephen Cobeldick on 16 Feb 2020
>> [~,idx] = ismember(a,x)
idx =
2 5 1 1

Sign in to comment.

More Answers (0)

Sign in to answer this question.