3.2. Scalars and Vectors

A scalar is a (1 × 1) matrix containing a single element only. A column vector is a (m × 1) matrix that has m number of rows but a single column only. A row vector is a (1 × n) matrix which has n number of columns and has only one row.

3.2.1. Assigning Data to Elements of a Vector/Scalar

All the elements of a row vector are separated by blank spaces or commas and are enclosed in square brackets.

For example, a row vector q = [1 2 4] can be entered at the Command Window as follows:

 q = [1 2 4];
orq = [1,2,4]

All the elements of a column vector are separated by semicolons and are enclosed in square brackets. For example, a column vector q is entered, as follows:

q = [1; 2; 4];

Variable q is a column vector and has one ...

Get MATLAB® and Its Applications in Engineering: [Based on MATLAB 7.5 (R2007b)] now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.