MATLAB Data Types

MATLAB Tutorial

🧬 MATLAB Data Types

MATLAB Data Types define what kind of data a variable can store (numbers, text, logical values, arrays, etc.).

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

class(a)
class(b)

📌 Output

ans = double
ans = double

📍 Default numeric type in MATLAB is double.


🔹 Other Numeric Types



 


2️⃣ Character (char) Data Type

Used to store text using single quotes.

🔸 Example



 

📌 Output

MATLAB

3️⃣ String Data Type

Used to store text using double quotes.

🔸 Example



 

📌 Output

Surat

📍 Strings support advanced text operations.


4️⃣ Logical Data Type

Used for true/false values.

🔸 Example



 

📌 Output

logical
1
logical
0

5️⃣ Vector Data Type

A one-dimensional array.

🔸 Example



 

📌 Output

1 2 3 4

6️⃣ Matrix Data Type

Two-dimensional array.

🔸 Example



 

📌 Output

1 2
3 4

7️⃣ Cell Array

Stores different data types together.

🔸 Example



 

📌 Output

[10] 'MATLAB' [1]

8️⃣ Structure (struct)

Stores related data as fields.

🔸 Example



 

📌 Output

name: 'Amit'
age: 20

🔍 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:

  • char uses single quotes ' '

  • string uses 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

You may also like...