I want to calculate factorial of a large data set containing some NaN in between the data.

3 ビュー (過去 30 日間)
example : data set
7
8
95
210
85
NaN
NaN
52
NaN

採用された回答

Guillaume
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 件)

madhan ravi
madhan ravi 2018 年 12 月 3 日
a=[7
8
95
210
85
NaN
NaN
52
NaN]
factorial(a(~isnan(a))) % why not this?
  2 件のコメント
Abhijeet Kumar
Abhijeet Kumar 2018 年 12 月 4 日
sir your answer is correct but it is ignoring the NaN values in final answer and reducing the data size form 9 to 6.
madhan ravi
madhan ravi 2018 年 12 月 4 日
Ah now i know what you want , cheers :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by