Borrar filtros
Borrar filtros

How to compare value for two variable?

10 visualizaciones (últimos 30 días)
Tan Wen Kun
Tan Wen Kun el 6 de Dic. de 2015
Editada: Tan Wen Kun el 6 de Dic. de 2015
matrix=
1 1 2 2
1 1 2 2
1 1 2 2
I got a matrix that store label 1 and 2 have mean value
meanR(1) = 10.33
meanG(1) = 20.33
meanB(1) = 30.33
meanR(2) = 12.33
meanG(2) = 23.33
meanB(2) = 34.33
so how I can compare both label?
what is the function name in matlab for compare?
what is the syntax for and(& or &&) in if operation?
if compare((meanR(1),meanR(2)<=5) && (meanR(1),meanR(2)<=5) && (meanR(1),meanR(2)<=5))
chg all label 2 to 1
result =
1 1 1 1
1 1 1 1
1 1 1 1
  2 comentarios
Jan
Jan el 6 de Dic. de 2015
The question is not clear. I cannot guess, what the "compare" operator should do. Why do you check if "meanR(2) <= 5"?
Tan Wen Kun
Tan Wen Kun el 6 de Dic. de 2015
Editada: Tan Wen Kun el 6 de Dic. de 2015
I want to compare whether the meanR, meanG, meanB value of label 1 and label 2 is within 5 or not? If this 3 statement true then I assign label 2 to label 1.

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 6 de Dic. de 2015
I presume you intended the three variables, not the same variable three times...simplest would be to first change storage/naming to not have to deal with three separate variables but only one. So first write
mnRGB=[meanR;meanB;meanG]; % or better yet, define this way from git-go instead
Then, the test is simply
if all(diff(mnRGB,2)<=5))
matrix(matrix==2)=1;
end
Above is a signed comparison, if it's an absolute or magnitude-only test wanted, then encapsulate the diff() operation inside abs of course.
See
doc if
doc diff
doc all
for details on syntax and Matlab's definition of TRUE for arrays and vectors.

Categorías

Más información sobre AI for Signals en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by