How to do Matrix calculations IF certain conditions are present.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 23 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!