I have a vector, say [1,2,710]. When I take exp([1,2,710]), I obtain ans=[2.7183,7.2891,Inf]. As the final answer is a very large number, I want to detect it first and reset it to a very large value, say 1e+305. I use isinf to help me, but isinf(ans) gives all 0. What should I do to solve the problem? Note that the input vector may change.

Try this:

```
maximum_num = 99999;
vec = [1,2,710];
expVec = exp(vec);
expVec(expVec > maximum_num) = maximum_num;
```

`maximum_num`

stores the largest value you allow in your vector. so if your working with double your can simply use `maximum_num= realmax`

instead of the first line of code.

`isinf(exp([1,2,710]))`

returns`[0 0 1]`

. And the function`isfinite`

work the same in reverse:`isfinite(exp([1,2,710]))`

=>`[1 1 0]`

. My guess is that`ans`

does not hold what you think (you probably overwrote it already). Do not use`ans`

. Name your variables adequately and do your operations on them.`realmax`