looking for equivalent in MATLAB of "where variable1 in ('a', 'b','c')" in SQL

6 ビュー (過去 30 日間)
Binzi Shu
Binzi Shu 2016 年 2 月 18 日
回答済み: Arnab Sen 2016 年 2 月 22 日
new to matlab. If I'm in SQL I would write "select ... where variable1 in ('a', 'b','c')". How does that translate in to matlab syntax? Thanks.
  1 件のコメント
jgg
jgg 2016 年 2 月 18 日
Probably ismember is the function you want? I don't know SQL very well, but if you want to select or check whether a variable is a member of a set you can use this or find.

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

回答 (1 件)

Arnab Sen
Arnab Sen 2016 年 2 月 22 日
Hi Binzi,
I understand from the query that you have two arrays and you would like to find out the elements in the first array which is also present in the second array.
You may use the function 'ismember' for this purpose.
You may refer to the following code snippet:
>>Variable1=[ 'b','e','a']; >>B=['a','b','c']; >>[Lia,Locb] = ismember(Variable1,B) Variable 'Lia' returns logical 1 for each match and 'Locb' returns the index of the elements in 'B' for each match.
You can use 'find' function to get the index in 'Variable' for matching elements as below.
>>A=find(Lia);
For more details about 'ismember', refer to the following link: http://www.mathworks.com/help/matlab/ref/ismember.html

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by