how to check that difference of two vectors is a multiple of ones in matlab
1 次查看(过去 30 天)
显示 更早的评论
A=[2 2 2 2 ] B=[3 3 3 3 ] want to check if A-B=k(ones) where k is an integer.
2 个评论
Stephen23
2018-9-7
"where k is an integer."
Can k be negative? Or zero? Or are only positive k allowed?
采纳的回答
Walter Roberson
2018-9-7
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 个评论
Walter Roberson
2018-9-7
t = A - B;
if t(1) ~= 0 && t(1) == fix(t(1)) && all(diff(t) == 0)
passed
else
failed
end
更多回答(1 个)
Alexander Jensen
2018-9-6
编辑:Alexander Jensen
2018-9-6
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!