I want to calculate factorial of a large data set containing some NaN in between the data.
조회 수: 1 (최근 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에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!