Locating entered vector values

조회 수: 1 (최근 30일)
Jose Grimaldo
Jose Grimaldo 2020년 2월 16일
댓글: Stephen23 2020년 2월 16일
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)));

채택된 답변

Bhaskar R
Bhaskar R 2020년 2월 16일
ind = find(ismember(x, a))
  댓글 수: 1
Stephen23
Stephen23 2020년 2월 16일
>> [~,idx] = ismember(a,x)
idx =
2 5 1 1

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by