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 日

1 投票

ind = find(ismember(x, a))

1 件のコメント

Stephen23
Stephen23 2020 年 2 月 16 日
>> [~,idx] = ismember(a,x)
idx =
2 5 1 1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

質問済み:

2020 年 2 月 16 日

コメント済み:

2020 年 2 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by