Matrix caculation about NAN and IFN
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Jialin Men
am 27 Jun. 2022
Kommentiert: Jialin Men
am 27 Jun. 2022
Hello everyone,
I have a question about Matrix cacluation.
I have two Matrix as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1047310/image.png)
C =A./B
so the elements from A divided by B element . than I get NAN and IFN.
How to ignore them?
Many many Thanks
JM
0 Kommentare
Akzeptierte Antwort
Karim
am 27 Jun. 2022
Bearbeitet: Karim
am 27 Jun. 2022
you can use indexing to avoid deviding by zero:
A = [1 0 0; 1 1 0; 3 4 2; 2 3 1];
B = [1 0 2;1 0 14; 0 1 11; 1 1 10];
C = zeros(size(A));
% find indexes of non zero locations
B_logi = B ~=0;
C(B_logi) = A(B_logi) ./ B(B_logi);
% display result
C
3 Kommentare
Karim
am 27 Jun. 2022
A = [1 0 0; 1 1 0; 3 4 2; 2 3 1];
B = [1 0 2;1 0 14; 0 1 11; 1 1 10];
C = zeros(size(A));
% find indexes of non zero locations
B_logi = B ~=0;
C(B_logi) = A(B_logi) ./ B(B_logi);
% find indexes of non zero locations
C_logi = C ~=0;
C_nonzero = C(C_logi)
histfit( C_nonzero(:) )
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!