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.

Type Size Range
int8 8-bit −128 to 127
int16 16-bit −32768 to 32767
int32 32-bit −2³¹ to 2³¹−1
int64 64-bit Very large
uint8 8-bit 0 to 255
uint16 16-bit 0 to 65535
uint32 32-bit 0 to 2³²−1
uint64 64-bit Very 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

Type Use
double Default, high precision
single Less precision, less memory
int8/int16/int32/int64 Signed integers
uint8/uint16/uint32/uint64 Unsigned integers
complex Real + imaginary numbers

You may also like...