Matrix comparison with unequal sized matrices

Hi
Let's say I have:
A = [A1, A2, A3, A4, A5]
B= [B1,B2,B4,B4,B5]
N = counter
If I want to:
  1. Compare B1 to A2. If B1 is greater than A2, increment N by 1. Else do nothing.
  2. Compare B2 to A3. If B2 is greater than A3, increment N by 1. Else do nothing.
  3. Compare B3 to A4. If B3 is greater than A4, increment N by 1. Else do nothing.
  4. Compare B4 to A5. If B4 is greater than A5, increment N by 1. Else do nothing.
  5. and ignore B5 since it has nothing to compare to
Is there a way to define above description in MATLAB...?
Thank you in advance

2 件のコメント

KSSV
KSSV 2020 年 10 月 26 日
Read about isequal.
Daniel Lee
Daniel Lee 2020 年 10 月 26 日
Will do. thank you!

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

 採用された回答

Stephen23
Stephen23 2020 年 10 月 26 日
編集済み: Stephen23 2020 年 10 月 26 日

0 投票

N = nnz(B(1:end-1)>A(2:end))
Tested:
>> A = randi(9,1,5)
A =
2 5 7 2 6
>> B = randi(9,1,5)
B =
3 9 5 5 4
>> N = nnz(B(1:end-1)>A(2:end))
N = 2

1 件のコメント

Daniel Lee
Daniel Lee 2020 年 10 月 26 日
thank you Stephen-- I'm going to have to study up on nnz function and randi function

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

リリース

R2020a

タグ

質問済み:

2020 年 10 月 26 日

コメント済み:

2020 年 10 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by