How to compare values in respective columns using "ismember"

3 ビュー (過去 30 日間)
Filip Hansson
Filip Hansson 2022 年 8 月 15 日
コメント済み: Filip Hansson 2022 年 8 月 15 日
I have a 24x365 matrix (A) and a 4x365 matrix (B). I would like to replace each of the same value from B in same column in A with "1" and the rest to be "0". I have tried using "ismember" but this registers and replaces values from B in A even if they are not in the respectively column. Is there a "simple" way to solve this problem??
Thank you in advanced!!

採用された回答

Bruno Luong
Bruno Luong 2022 年 8 月 15 日
use ismember on each column separately
for j=1:size(A,2)
A(:,j) = ismember(A(:,j),B(:,j));
end
  1 件のコメント
Filip Hansson
Filip Hansson 2022 年 8 月 15 日
Worked like a charm! Thanks alot!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by