Facing problem with Relational Operation

I am facing some problem in comparing difference of two variables with some threshold value. Here is the part of code belongs to it.
R_miss_old =
1.0e+003 *
Columns 1 through 8
0 0 0 0 0 0 0 0
Columns 9 through 16
0 0 0 0 0 0 0 1.3169
and
R_miss_new =
1.0e+003 *
Columns 1 through 8
0 0 0 0 0 0 0 0
Columns 9 through 16
0 0 0 0 0 0 0 1.1970
now I want to check whether the difference between above two is less than some threshold value (lets say d=0.001) or not for this I did
if (abs(R_miss_new-R_miss_old)<d)
disp('Smaller')
elseif (abs(R_miss_new-R_miss_old)>d)
disp('Greater')
end
But I am not getting any result. How can I perform this operation ? Did I make any mistake while calculating R_miss_old or R_miss_new ?

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 5 de Abr. de 2013
Editada: Azzi Abdelmalek el 5 de Abr. de 2013
use
if all(abs(R_miss_new-R_miss_old)<d)
You are comparing two vectors, what about this case?
R_miss_new=[1 2 3 4];
R_miss_old=[0 3 2 2]

5 comentarios

what is the meaning of following
R_miss_new =
1.0e+003 *
Columns 1 through 8
0 0 0 0 0 0 0 0
Columns 9 through 16
0 0 0 0 0 0 0 1.1970
I mean what is the value of first column ? The last column only has some value. Does this mean all other column has zero value ?
Azzi Abdelmalek
Azzi Abdelmalek el 5 de Abr. de 2013
Editada: Azzi Abdelmalek el 5 de Abr. de 2013
It does not mean they are equal to zero, To understand try this
a=10^3*[0.00001 1]
I used sum() to calculate R_miss_old and R_miss_new and why I am getting values in such format ? Here is the code that I have used to calculate R_miss_old
N=16;
p=1;
fs=10000;
T=3000./fs;
Threshold=[1.1260 1.4548 1.1073 1.0567 1.1078 1.0898 1.1362 1.1259 1.2674 1.1234 1.1845 1.0882 1.1062 1.0690 1.0713 1.2786];
r=[857 206 853 900 611 808 561 325 212 391 219 830 308 650 924 138];
for k=1:N
Pf(k)=qfunc(((Threshold(k)./(p.^2))-1).*sqrt(t.*fs));
end
R_miss_old(k)=sum(r.*[Pf.*(1-(t./T))+(t./T)])
I am using sum() and why I am getting value in vector form ? I should get it in single form,shouldn't I ?
Do not use R_miss_old(k), Use R_miss_old
R_miss_old=sum(r.*[Pf.*(1-(t./T))+(t./T)])
Suwas Karki
Suwas Karki el 5 de Abr. de 2013
Yes you are right this is the simple mistake and after going through so many times from the top to bottom of my code I was not able to find it out :) Anyway thanks !!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by