I want to calculate factorial of a large data set containing some NaN in between the data.
2 次查看(过去 30 天)
显示 更早的评论
example : data set
7
8
95
210
85
NaN
NaN
52
NaN
0 个评论
采纳的回答
Guillaume
2018-12-3
编辑:Guillaume
2018-12-3
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.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!