How to find numbers from one matrix in another one?

1 回表示 (過去 30 日間)
Daria Ivanchenko
Daria Ivanchenko 2020 年 4 月 28 日
編集済み: KSSV 2020 年 4 月 28 日
Hi everyone!
I have to matrixes: the one is very huge and contains time data in the first column and zeros in the second column. The other matrix is smaller and contains other time numbers that I need (there is only one column). What I need to do is to find the numbers from the second matrix in the first one. And then mark them as "1" in the second column. How can I do this?
For example I have the firsrt matrix A = [1 2 3 4 5 6 7 8 9 10; 0 0 0 0 0 0 0 0 0 0]. And the second one B = [2 4 6]. I want to get in the end the matrix that will have ones instead of zeros in the places of the second matrix: A = [1 2 3 4 5 6 7 8 9 10; 0 1 0 1 0 1 0 0 0 0].
Thanks for your help!

回答 (1 件)

KSSV
KSSV 2020 年 4 月 28 日
編集済み: KSSV 2020 年 4 月 28 日
[idx,ia] = ismember(A(1,:),B) ;
A(2,idx) = 1 ;

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by