Filter löschen
Filter löschen

how to check that difference of two vectors is a multiple of ones in matlab

1 Ansicht (letzte 30 Tage)
A=[2 2 2 2 ] B=[3 3 3 3 ] want to check if A-B=k(ones) where k is an integer.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Sep. 2018
Check that the first entry of A-B is an integer with mod() or by comparing it to fix() of itself. Then check that diff() of A-B is all zero.

Weitere Antworten (1)

Alexander Jensen
Alexander Jensen am 6 Sep. 2018
Bearbeitet: Alexander Jensen am 6 Sep. 2018
Is this what you're looking for?:
isInt = ~logical(mod(A-B,1))
isInt =
1×4 logical array
0 1 1 1
The logical(X) function returns everything that is not 0 as TRUE.
  1 Kommentar
asim nadeem
asim nadeem am 7 Sep. 2018
if A= [2 6], B=[6 2] then A-B=[-4 4] so A-B is not an integer multiple of ones as if we take 4 common we get 4*[-1 1]. how can I check it for arbitrary A and B. so if it is multiple of ones then I need 0 or 1 single answer

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by