A Matrix is a two-layered cluster of numbers. In MATLAB, we can create a Matrix by entering components in each line as comma or space-delimited numbers and also, utilizing semicolons to stamp the finish of each line.
Approach:
- Step 1: Pick 2 elements in a row using logical()
- Step 2: Get all possible Combinations using perms()
- Step 3: Pick 5 Random Numbers from 1 to 24 using Randi() function
- Step 4: Logical Index to Pick Numbers in Each Row
- Step 5: Create A Matrix (Original)
- Step 6: Transpose the Matrix
- Step 7: Pick the Data. Each column contains two numbers from each row in the matrix A
- Step 8: Swap the values
- Step 9: Fill Back the Data
- Step 10: Transpose to give the Final Result
Example:
Output:
👁 Image