필터 지우기
필터 지우기

Ho to compare two array with tolerance?

조회 수: 4 (최근 30일)
Namrata Biranje
Namrata Biranje 2018년 5월 8일
댓글: Stephen23 2018년 5월 8일
I have two 2 dimensional arrays as follows: at time step 0.1 to 1.1
A = [0 0 0 1 1 1 0 0 0 1 1 0 0 0..] B = [0 0 0 0 0 1 1 1 0 0 0 1 1 0..]
One more array Diff which is the differance of A and B Diff = [0 0 0 1 1 0 -1 -1 0 1 1 -1 -1 0...]
my logic is
lwrlmt=-0.3 upperlmt = 0.3
for j=1:length(Diff)
if (Diff(j,2)~= 0)
if (Diff(j-1,2)==0) && (Diff(j+1,2)~=0)
Tm1 = Diff(j,1); % if here TM1 = 0.4
end
if (Diff(j-1,2)~=0)&& (Diff(j+1,2)==0)
Tm2 = Diff(j,1); % Tm2= 0.5
Rais_diff=(Tm2-Tm1)*1000; %0.5-0.4=0.1
R_temp=int2str(Rais_diff);
Tolerance = str2double(R_temp);
if ((lwrlmt<=Tolerance) && (Tolerance<=upperlmt))
disp('A and B are equal');
else
disp('A and B are not equal');
break;
end
end
end
But above logic is failing when Diff array is
[ 0 0 0 0 0 0 1 1 1 1 1 1 ..] or [ 1 1 1 1 1 1 1 0 0 0 0]
how should I proceed further?
  댓글 수: 2
Jan
Jan 2018년 5월 8일
All we see is the code, which does not do, what you want. But you forgot to mention, what you want instead.
Stephen23
Stephen23 2018년 5월 8일
@Namrata Biranje: please explain what you are trying to achieve, and explain the rules of what you want the code to do. Showing us broken code is not as helpful as you actually telling us in words what you want. Please also show us complete examples with inputs and outputs, so that we have something to run code on and compare against.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by