MATLAB Numeric Data Types
🔢 MATLAB Numeric Data Types
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
2️⃣ single
-
32-bit floating-point
-
Less precision
-
Uses less memory than double
Example
Output
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
Example: Unsigned Integer
Output
4️⃣ Complex Numbers
MATLAB supports complex numbers using i or j.
Example
Output
🔍 Checking Numeric Type & Size
Example Output:
🔄 Type Conversion Examples
Double → Integer
Output
Integer → Double
Output
⚠️ 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 |
