Ho to compare two array with tolerance?

3 次查看(过去 30 天)
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