Ho to compare two array with tolerance?

2 ビュー (過去 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 Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by