MATLAB Numeric Data Types

MATLAB Tutorial

🔢 MATLAB Numeric Data Types

Numeric data types in MATLAB are used to store numbers such as integers, decimals, and floating-point values.

MATLAB is developed by MathWorks.


🔹 What Are Numeric Data Types?

Numeric data types define:

  • How numbers are stored

  • Memory size

  • Range and precision

MATLAB automatically assigns double unless specified otherwise.


📌 Main Numeric Data Types in MATLAB

1️⃣ double (Default Data Type)

  • 64-bit floating-point

  • High precision

  • Most commonly used

Example


Output

10
3.1416
ans = double

2️⃣ single

  • 32-bit floating-point

  • Less precision

  • Uses less memory than double

Example


Output

5.75
ans = single

3️⃣ Integer Data Types

Used to store whole numbers only.

TypeSizeRange
int88-bit−128 to 127
int1616-bit−32768 to 32767
int3232-bit−2³¹ to 2³¹−1
int6464-bitVery large
uint88-bit0 to 255
uint1616-bit0 to 65535
uint3232-bit0 to 2³²−1
uint6464-bitVery large

Example: Signed Integer


Output

100
ans = int8

Example: Unsigned Integer


Output

200
ans = uint8

4️⃣ Complex Numbers

MATLAB supports complex numbers using i or j.

Example


Output

3.0000 + 4.0000i

🔍 Checking Numeric Type & Size

whos

Example Output:

Name Size Bytes Class
a 1x1 8 double
b 1x1 1 uint8

🔄 Type Conversion Examples

Double → Integer


Output

12

Integer → Double


Output

ans = double

⚠️ Important Notes

  • Decimal values are truncated when converted to integers

  • Default numeric type is double

  • Integer types save memory but have limited range


🎯 Interview Questions: MATLAB Numeric Data Types

🔹 Q1. What is the default numeric data type in MATLAB?

Answer: double


🔹 Q2. Difference between single and double?

Answer:

  • single → 32-bit, less precision

  • double → 64-bit, high precision


🔹 Q3. Which data type uses least memory?

Answer: int8 or uint8


🔹 Q4. Can MATLAB store complex numbers?

Answer: Yes, using i or j.


🔹 Q5. What happens when converting double to integer?

Answer: Decimal part is removed (truncation).


🔹 Q6. How do you check numeric data type?

Answer: Using class() or whos.


🔹 Q7. When should integer types be used?

Answer: When memory efficiency and fixed range values are required.


Summary Table

TypeUse
doubleDefault, high precision
singleLess precision, less memory
int8/int16/int32/int64Signed integers
uint8/uint16/uint32/uint64Unsigned integers
complexReal + imaginary numbers

You may also like...