Matrix Manipulation in MATLAB
🔧 Matrix Manipulation in MATLAB
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
📌 Converts rows into columns.
2️⃣ Reshaping a Matrix – reshape()
Changes matrix dimensions without changing data.
Output
📌 Number of elements must remain the same.
3️⃣ Concatenating Matrices
🔸 Horizontal Concatenation
Output
🔸 Vertical Concatenation
Output
4️⃣ Adding Rows and Columns
🔸 Add a Row
Output
🔸 Add a Column
Output
5️⃣ Deleting Rows and Columns
🔸 Delete Row
🔸 Delete Column
6️⃣ Replacing Matrix Elements
Output
7️⃣ Sorting a Matrix
Output
8️⃣ Flipping a Matrix
🔸 Flip Left–Right
🔸 Flip Up–Down
9️⃣ Finding Size & Length
⚠️ 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
