## hypothetical matlab's limit

Bio_Ing_Sapienza

### Bio_Ing_Sapienza (view profile)

さんによって質問されました 2019 年 2 月 9 日

### John D'Errico (view profile)

さんによって コメントされました 2019 年 2 月 9 日
Hi everyone. I have to calculate a sumof a vector of doubles of 1x4884 components. When I use this function i get as ans=nan. I there a limit to the maximum number that matlab is able to calculate? If yes how can i change this cobstraint?

#### 1 件のコメント

2019 年 2 月 9 日

サインイン to comment.

## 1 件の回答

2019 年 2 月 9 日

2019 年 2 月 9 日

I'm sure there is such a limit in Matlab but it's nowhere near a vector length of 4884.
The problem is that you have at least 1 NaN value in your data.
sum([1, NaN])
ans =
NaN
Use the 'omitnan' flag to ignore NaN values.
sum([1,NaN], 'omitnan')
ans =
1
To confirm that you have at least one NaN value in your data, if this next line returns True (1), you have NaN value(s).
any(isnan(yourData)) % to find where the NaNs are: find(isnan(yourData))
And here's a test to confirm that Matlab can handle vector lengths of 4884 (or even 4884000 for that matter).
sum(rand(1, 4884))

John D'Errico

### John D'Errico (view profile)

2019 年 2 月 9 日
The trick to remember is anytime you have an indeterminate result, you should get NaN.
So inf+inf is just bigger than inf, but nothing is bigger than inf. Even inf^inf does not roll into a NaN.
inf^inf
ans =
Inf
inf^(-inf)
ans =
0
I was actually wondering if that latter one would go into a NaN, but it did not, nor did these:
inf^0
ans =
1
0^inf
ans =
0
The NaN producers I can think of are...
inf - inf
ans =
NaN
inf/inf
ans =
NaN
0*inf
ans =
NaN
sin(inf)
ans =
NaN
cos(inf)
ans =
NaN
tan(inf)
ans =
NaN
And of course the classic:
0/0
ans =
NaN