I want to calculate factorial of a large data set containing some NaN in between the data.
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Abhijeet Kumar
 am 3 Dez. 2018
  
    
    
    
    
    Kommentiert: madhan ravi
      
      
 am 4 Dez. 2018
            example : data set
7
8
95
210
85
NaN
NaN
52
NaN
0 Kommentare
Akzeptierte Antwort
  Guillaume
      
      
 am 3 Dez. 2018
        
      Bearbeitet: Guillaume
      
      
 am 3 Dez. 2018
  
      I would assume you want an output the same size as the input, in which case:
V = [7     8    95   210    85   NaN   NaN    52   NaN]'  %demo data
result = nan(size(v));
result(~isnan(v)) = factorial(v(~isnan(v)))
As documented factorial is only exact for input less than or equal to 21. factorial([95, 85, 52]) gives you an inaccurate result but with the correct order of magnitude. factorial(210) is far beyound what can be stored as double precision. Anything above factorial(171) is too big.
Weitere Antworten (1)
  madhan ravi
      
      
 am 3 Dez. 2018
        a=[7
8
95
210
85
NaN
NaN
52
NaN]
factorial(a(~isnan(a))) % why not this?
2 Kommentare
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!

