MATLAB Data Types
🧬 MATLAB Data Types
MATLAB is developed by MathWorks.
🔹 What Are Data Types in MATLAB?
A data type specifies:
-
The type of data
-
The size in memory
-
The operations that can be performed
MATLAB automatically assigns data types when values are stored.
📂 Main MATLAB Data Types
1️⃣ Numeric Data Types
Used to store numbers.
🔸 Example
🔸 Check Type
📌 Output
📍 Default numeric type in MATLAB is double.
🔹 Other Numeric Types
2️⃣ Character (char) Data Type
Used to store text using single quotes.
🔸 Example
📌 Output
3️⃣ String Data Type
Used to store text using double quotes.
🔸 Example
📌 Output
📍 Strings support advanced text operations.
4️⃣ Logical Data Type
Used for true/false values.
🔸 Example
📌 Output
5️⃣ Vector Data Type
A one-dimensional array.
🔸 Example
📌 Output
6️⃣ Matrix Data Type
Two-dimensional array.
🔸 Example
📌 Output
7️⃣ Cell Array
Stores different data types together.
🔸 Example
📌 Output
8️⃣ Structure (struct)
Stores related data as fields.
🔸 Example
📌 Output
🔍 Checking Data Type
🔄 Type Conversion
🎯 Interview Questions on MATLAB Data Types
🔹 Q1. What is the default numeric data type in MATLAB?
Answer: double
🔹 Q2. Difference between char and string in MATLAB?
Answer:
-
charuses single quotes' ' -
stringuses double quotes" "and supports advanced operations
🔹 Q3. What data type stores true/false values?
Answer: Logical data type.
🔹 Q4. What function is used to check data type?
Answer: class()
🔹 Q5. Can It store multiple data types in one variable?
Answer: Yes, using cell arrays and structures.
🔹 Q6. How do you convert numeric to string?
Answer: Using num2str().
🔹 Q7. What is the difference between vector and matrix?
Answer:
-
Vector → 1D array
-
Matrix → 2D array
🔹 Q8. Which command shows variable size and data type?
Answer: whos
✅ Summary Table
| Data Type | Description |
|---|---|
| double | Default numeric |
| char | Text (single quotes) |
| string | Text (double quotes) |
| logical | true / false |
| vector | 1D array |
| matrix | 2D array |
| cell | Mixed data |
| struct | Structured data |
