q matrices element matching

1 回表示 (過去 30 日間)
PRAVEEN GUPTA
PRAVEEN GUPTA 2019 年 8 月 28 日
コメント済み: PRAVEEN GUPTA 2019 年 8 月 28 日
i have a matrix like
A=[1 2 3 4 5;
1 2 3 4 6
1 3 4 5 8];
i want a output like X=[1 2 3 4 0]
i.e. i need the common element in the particular coloumn if there is no particular coloum result must b zero

採用された回答

Walter Roberson
Walter Roberson 2019 年 8 月 28 日
X = zeros(1, size(A,2));
mask = A(1,:) == A(2,:) | A(1,:) == A(3,:);
X(mask) = A(1,mask);
mask = A(2,:) == A(3,:);
X(mask) = A(2,mask);
  1 件のコメント
PRAVEEN GUPTA
PRAVEEN GUPTA 2019 年 8 月 28 日
thanks

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2019 年 8 月 28 日
I suspect this is a homework assignment so I'm only going to give a hint. You want the most common element as long as it appears multiple times? The mode function may be of use to you.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by