MATLAB Function Reference |

Control state of integer warnings

**Syntax**

**Description**

MATLAB has four types of integer warnings. The `intwarning`

function enables, disables, or returns information on these warnings:

`MATLAB:intConvertNaN`

-- Warning on an attempt to convert NaN (Not a Number) to an integer. The result of the operation is zero.`MATLAB:intConvertNonIntVal`

-- Warning on an attempt to convert a non-integer value to an integer. The result is that the input value is rounded to the nearest integer for that class.`MATLAB:intConvertOverflow`

-- Warning on overflow when attempting to convert from a numeric class to an integer class. The result is the maximum value for the target class.`MATLAB:intMathOverflow`

-- Warning on overflow when attempting an integer arithmetic operation. The result is the maximum value for the class of the input value. MATLAB also issues this warning when NaN is computed (e.g.,`int8(0)/0`

).

`intwarning('`

sets or displays the state of integer warnings in MATLAB according to the string,

')
*action*

. There are three possible actions, as shown here. The default state is *action*`'off'`

.

Action |
Description |

`off` |
Disable the display of integer warnings |

`on` |
Enable the display of integer warnings |

`query` |
Display the state of all integer warnings |

`s = intwarning('`

sets the state of integer warnings in MATLAB according to the string

')
*action*

, and then returns the previous state in a 4-by-1 structure array, *action*`s`

. The return structure array has two fields: `identifier`

and `state`

.

```
intwarning(s)
```

sets the state of integer warnings in MATLAB according to the `identifier`

and `state`

fields in structure array `s`

.

```
sOld = intwarning(sNew)
```

sets the state of integer warnings in MATLAB according to `sNew`

, and then returns the previous state in `sOld`

.

**Remarks**

**General Usage**

Examples of the four types of integer warnings are shown here:

Attempt to convert NaN (Not a Number) to an unsigned integer:

Attempt to convert a floating point number to an unsigned integer:

Attempt to convert a large unsigned integer to a signed integer, where the operation overflows:

Attempt an integer arithmetic operation that overflows:

**Example 1**

Check the initial state of integer warnings:

intwarning('query') The state of warning 'MATLAB:intConvertNaN' is 'off'. The state of warning 'MATLAB:intConvertNonIntVal' is 'off'. The state of warning 'MATLAB:intConvertOverflow' is 'off'. The state of warning 'MATLAB:intMathOverflow' is 'off'.

Convert a floating point value to an 8-bit unsigned integer. MATLAB does the conversion, but that requires rounding the resulting value. Because all integer warnings have been disabled, no warning is displayed:

Store this state in structure array `iwState`

:

Change the state of the `ConvertNonIntVal`

warning to `'on'`

by first setting the state to `'on'`

in the `iwState`

structure array, and then loading `iwState`

back into the internal integer warning settings for your MATLAB session:

maxintwarn = 4; for k = 1:maxintwarn if strcmp(iwState(k).identifier, 'MATLAB:intConvertNonIntVal') iwState(k).state = 'on'; intwarning(iwState); end end

Verify that the state of `ConvertNonIntVal`

has changed:

intwarning('query') The state of warning 'MATLAB:intConvertNaN' is 'off'. The state of warning 'MATLAB:intConvertNonIntVal' is 'on'. The state of warning 'MATLAB:intConvertOverflow' is 'off'. The state of warning 'MATLAB:intMathOverflow' is 'off'.

Now repeat the conversion from floating point to integer. This time MATLAB displays the warning:

uint8(2.7) Warning: Conversion rounded non-integer floating point value to nearest uint8 value. ans = 3

**See Also **

intmin | inv |

© 1994-2005 The MathWorks, Inc.