How to do Matrix calculations IF certain conditions are present.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have 2 matrices A and B and want to do A./B But some values in B are zero, producing inf then, in later calculations, NaN.
I think I can find the zero values using a logical matrix (learning it!) but I don't know how to use that information.
How do I do; If value_in_matrix_B is not zero, do A./B
Or more generally, how do I do IF such_and_such_condition applies to a particular position THEN do That;
Jonathan.
0 comentarios
Respuestas (1)
Walter Roberson
el 23 de Jun. de 2013
value_in_matrix_B = B(J,K);
if value_in_matrix_B ~= 0
A ./ value_in_matrix_B
end
If you are talking about doing this using logical indexing, then:
nzB = B ~= 0;
A(nzB) ./ B(nzB)
but what about the places where it is 0 ?
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!