Searching different elements from array.

3 ビュー (過去 30 日間)
Andre
Andre 2014 年 4 月 2 日
編集済み: Joseph Cheng 2014 年 4 月 2 日
Hi,
I have an array, and I want a new array with matches from another array.
Like,
array=[12 3 4 8 9 3 3 4 1]
search=[4 9 3]; % numbers that i want to match...
new_array=matches(array, search); % matches is a function or an script...
new_array would be [0 0 1 0 0 1 1 0 0].
There is a function for it?
Andre

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 2 日
編集済み: Azzi Abdelmalek 2014 年 4 月 2 日
array=[12 3 4 8 9 3 3 4 1]
search=[4 9 3];
ismember(array,search)

その他の回答 (1 件)

Joseph Cheng
Joseph Cheng 2014 年 4 月 2 日
編集済み: Joseph Cheng 2014 年 4 月 2 日
your example doesn't really make sense as
array=[12 3 4 8 9 3 3 4 1]
search=[4 9 3];
doesn't give you your answer if you are looking for the values of search in array and marking them 1.
your answer should be [0 1 1 0 1 1 1 1 0] correct?
array=[12 3 4 8 9 3 3 4 1]
ans =[ 0 1 1 0 1 1 1 1 0]; %highlighting 3,4 and 9
ismember() function will do what you are looking for even though your example doesn't make sense.

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by