Ho to compare two array with tolerance?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Jan
el 8 de Mayo de 2018
All we see is the code, which does not do, what you want. But you forgot to mention, what you want instead.
Stephen23
el 8 de Mayo de 2018
@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.
Respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!