How to do Matrix calculations IF certain conditions are present.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 23 Juin 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 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!