compare the absolute value of each element from two matrices
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jack_111
el 25 de Nov. de 2014
Comentada: Image Analyst
el 25 de Nov. de 2014
I have two matrices A and B with the size NxM and I want to compare the absolute value of each element for the two matrices and return the bigger value and then to store the real value in a new matrix.
Any suggestions please
Many thanks in advance
3 comentarios
Image Analyst
el 25 de Nov. de 2014
OK. Good. Calling it the "real" value instead of the "max" value was a major oversight initially. But now that you've clarified it, it looks like you now have two correct solutions. Thanks for accepting one of them. You can also vote for both of them too, even though you can accept only one.
Respuesta aceptada
Guillaume
el 25 de Nov. de 2014
Editada: Guillaume
el 25 de Nov. de 2014
Concatenate A and B along the third dimension, get the second output of max along the 3rd dimension of the absolute of that 3d matrix to get the z index. The tricky bit is then using that z value to select A or B. Summing each matrix multiplied by a logical matrix should do it:
a = [1 -2 -3; 4 5 -6]
b = [3 2 1; 8 9 -3]
ab = cat(3, a, b);
[~, idx] = max(abs(ab), [], 3);
c = a.*(idx==1) + b.*(idx==2)
0 comentarios
Más respuestas (1)
the cyclist
el 25 de Nov. de 2014
Editada: the cyclist
el 25 de Nov. de 2014
absA = abs(A);
absB = abs(B);
I'm not sure what you mean by "compare ... and return the real value". Larger? Smaller? Difference?
2 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!