Help comparing two matrices

3 ビュー (過去 30 日間)
Antonio
Antonio 2014 年 12 月 22 日
編集済み: Antonio 2014 年 12 月 22 日
so I need to compare two matrices but I need to set the values the final compared matrice will have... so for example if one value is higher than the other it should display 1; if it is lower -1 and finally if it is equal 0. I have been messing with this but cant figure it out I think I need a way to go over the two matrices comparing the two elements and but then how do I set those elements back into a matrice....? why is it so complicated!!!
well i need a function... sorry and thanks for the quick responses

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 12 月 22 日
編集済み: Azzi Abdelmalek 2014 年 12 月 22 日
idxp=A>B
idxn=A<B
C=zeros(size(A))
C(idxp)=1;
C(idxn)=-1

その他の回答 (1 件)

Roger Stafford
Roger Stafford 2014 年 12 月 22 日
C = sign(A-B);

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by