Vectors in MATLAB

📐 Vectors in MATLAB
MATLAB is developed by MathWorks.
🔹 What Is a Vector in MATLAB?
A vector is a collection of elements arranged in one row or one column.
Row Vector → 1 × n
Column Vector → n × 1
1️⃣ Creating Vectors
🔸 Row Vector
Output
🔸 Column Vector
Output
🔸 Using Colon Operator
Output
🔸 With Step Size
Output
2️⃣ Vector Indexing & Accessing Elements
Output
📌 Indexing in MATLAB starts from 1.
3️⃣ Vector Operations
🔸 Addition & Subtraction
Output
🔸 Element-wise Multiplication
Output
🔸 Scalar Operation
Output
4️⃣ Common Vector Functions
Length of Vector
Sum & Mean
Maximum & Minimum
5️⃣ Transpose of a Vector
Output
6️⃣ Logical Operations on Vectors
Output
⚠️ Important Notes
Vectors must be of same size for element-wise operations
Use
.*,./,.^for element-wise mathMATLAB indexing starts at 1
🎯 Interview Questions: Vectors in MATLAB
Q1. What is a vector in MATLAB?
Answer: A one-dimensional array of elements.
Q2. Difference between row and column vector?
Answer:
Row vector → 1×n, Column vector → n×1.
Q3. How do you create a vector from 1 to 10?
Answer: v = 1:10;
Q4. How do you access the 4th element of a vector v?
Answer: v(4)
Q5. What operator is used for element-wise multiplication?
Answer: .*
Q6. How do you find the length of a vector?
Answer: Using length().
Q7. What is the index of the first element in MATLAB?
Answer: 1
✅ Summary
Vectors are 1D arrays
Can be row or column
Support fast mathematical operations
Widely used in engineering & data analysis
