0
0
MATLABdata~5 mins

Row and column vectors in MATLAB

Choose your learning style9 modes available
Introduction

Row and column vectors help organize numbers in a line horizontally or vertically. They make math with lists of numbers easy.

When you want to store a list of numbers in one row.
When you need to perform matrix math with vertical lists.
When you want to input data for plotting in MATLAB.
When you want to organize data for calculations like sums or averages.
Syntax
MATLAB
Row vector: rowVec = [1 2 3 4];
Column vector: colVec = [1; 2; 3; 4];

Use spaces or commas to separate elements in a row vector.

Use semicolons to separate elements in a column vector.

Examples
This creates a row vector with four numbers in one horizontal line.
MATLAB
rowVec = [5 10 15 20];
This creates a column vector with four numbers stacked vertically.
MATLAB
colVec = [5; 10; 15; 20];
You can also use commas to separate elements in a row vector.
MATLAB
rowVec = [1, 2, 3, 4];
Sample Program

This program creates a row vector and a column vector, then prints them to show their shapes.

MATLAB
rowVec = [1 2 3 4];
colVec = [1; 2; 3; 4];

% Display the vectors
disp('Row vector:');
disp(rowVec);
disp('Column vector:');
disp(colVec);
OutputSuccess
Important Notes

Row vectors look like a horizontal list: [a b c].

Column vectors look like a vertical list: [a; b; c].

You can convert between them using the transpose operator: rowVec' becomes a column vector.

Summary

Row vectors store numbers horizontally using spaces or commas.

Column vectors store numbers vertically using semicolons.

They are basic building blocks for math and data in MATLAB.