how to check that difference of two vectors is a multiple of ones in matlab
    조회 수: 5 (최근 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에서 Logical에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



