how to check that difference of two vectors is a multiple of ones in matlab
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
asim nadeem
am 6 Sep. 2018
Kommentiert: Walter Roberson
am 7 Sep. 2018
A=[2 2 2 2 ] B=[3 3 3 3 ] want to check if A-B=k(ones) where k is an integer.
2 Kommentare
Stephen23
am 7 Sep. 2018
"where k is an integer."
Can k be negative? Or zero? Or are only positive k allowed?
Akzeptierte Antwort
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.
1 Kommentar
Walter Roberson
am 7 Sep. 2018
t = A - B;
if t(1) ~= 0 && t(1) == fix(t(1)) && all(diff(t) == 0)
passed
else
failed
end
Weitere Antworten (1)
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.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!