Matrix Manipulation in MATLAB

MATLAB Tutorial

🔧 Matrix Manipulation in MATLAB

Matrix manipulation in MATLAB refers to modifying, reshaping, combining, and transforming matrices to perform calculations efficiently.

MATLAB is developed by MathWorks.


🔹 What Is Matrix Manipulation?

Matrix manipulation includes:

  • Changing size or shape

  • Adding, deleting, or replacing rows/columns

  • Rearranging elements

  • Performing transformations


1️⃣ Matrix Transpose

🔸 Example



 

Output

1 4
2 5
3 6

📌 Converts rows into columns.


2️⃣ Reshaping a Matrix – reshape()

Changes matrix dimensions without changing data.



 

Output

1 3 5
2 4 6

📌 Number of elements must remain the same.


3️⃣ Concatenating Matrices

🔸 Horizontal Concatenation



 

Output

1 2 3 4

🔸 Vertical Concatenation



 

Output

1 2
3 4

4️⃣ Adding Rows and Columns

🔸 Add a Row



 

Output

1 2
3 4
5 6

🔸 Add a Column



 

Output

1 2 7
3 4 8
5 6 9

5️⃣ Deleting Rows and Columns

🔸 Delete Row



 


🔸 Delete Column



 


6️⃣ Replacing Matrix Elements



 

Output

10 99
30 40

7️⃣ Sorting a Matrix



 

Output

1 2 3
4 5 6

8️⃣ Flipping a Matrix

🔸 Flip Left–Right

fliplr(A)

🔸 Flip Up–Down

flipud(A)

9️⃣ Finding Size & Length

size(A)
length(A)

⚠️ Important Notes

  • Matrix dimensions must be compatible

  • reshape() does not change data order (column-wise)

  • MATLAB indexing starts at 1

  • Use vectorized operations for better performance


🎯 Interview Questions: Matrix Manipulation in MATLAB

🔹 Q1. What is matrix manipulation?

Answer:
The process of modifying or transforming matrices.


🔹 Q2. What does reshape() do?

Answer:
Changes matrix dimensions without changing elements.


🔹 Q3. Difference between horizontal and vertical concatenation?

Answer:
Horizontal → same rows, Vertical → same columns.


🔹 Q4. How do you delete a column?

Answer:
A(:,column_number) = []


🔹 Q5. What does transpose do?

Answer:
Converts rows into columns.


🔹 Q6. How do you add a new row?

Answer:
A(new_row,:) = values


🔹 Q7. Which function flips a matrix vertically?

Answer:
flipud()


Summary

  • Matrix manipulation is core to MATLAB

  • Supports reshape, transpose, concatenate, delete

  • Helps in data processing & numerical computation

  • Widely used in engineering & scientific analysis

You may also like...