How to eliminate Nan
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Gliq=(R*T*((x(1)*log(x(1)))+(x(2)*log(x(2)))+(x(3)*log(x(3)))+(x(4)*log(x(4)))+(x(5)*log(x(5)))+(x(6)*log(x(6)))+(x(7)*log(x(7)))+(x(8)*log(x(8)))));
for x=[0.162071097716028  0  0.276531475376737  0  0.264268578570244  0.247172330667782  0.0276055958119857  0.0223509218572239];
This code produces NaNs because of taking the natural log of zeros.
Can somebody help me how to eliminate Nans?
2 Kommentare
  James Tursa
      
      
 am 16 Mär. 2018
				What would you like to have happen for those spots? Replace the NaN's with something else? Delete the NaN's from the result (i.e., shrink the size of the result)? Or ...?
Antworten (2)
  Star Strider
      
      
 am 16 Mär. 2018
        One option:
x=[0.162071097716028  0  0.276531475376737  0  0.264268578570244  0.247172330667782  0.0276055958119857  0.0223509218572239];
x = x(x > 0);
4 Kommentare
  Image Analyst
      
      
 am 16 Mär. 2018
				I'm having trouble following all those thousands of parentheses. But it looks like the RT is multiplying the sum of all the terms, so do you mean
Gliq = R*T*sum(x.*log(x));
  Star Strider
      
      
 am 16 Mär. 2018
				That’s essentially it.
It uses ‘dot product’ (link) vector multiplication to multiply row vector ‘x’ by column vector ‘log(x(:))’.
Gliq = R*T*dot(x,log(x))
produces the same result.
  James Tursa
      
      
 am 16 Mär. 2018
        result = the stuff you are currently doing
result(isnan(result)) = [];
2 Kommentare
  James Tursa
      
      
 am 16 Mär. 2018
				"... This is not working ..." and "... Getting the same problem ..."
These comments do not help us since they give us no further detail into the issues you are having. Please show us your complete code, the current result you are getting, and then show us the result that you would like to get.
Siehe auch
Kategorien
				Mehr zu Data Type Conversion 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!



