0% found this document useful (0 votes)
55 views1 page

E.g: The Command y 1:5 Will Create The Row Vector (1 2 3 4 5) y 1:n:5 Will Have The Step Value of N. Note That If 1+n 5, y

The colon operator : is used to iterate through values with an optional step value. For example, 1:5 creates the vector [1 2 3 4 5] and 1:n:5 uses a step of n. The colon operator can also be used to select entire rows or columns from a matrix, such as A(:,4) to select the 4th column. linspace creates a linearly spaced vector between x and y with n number of elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views1 page

E.g: The Command y 1:5 Will Create The Row Vector (1 2 3 4 5) y 1:n:5 Will Have The Step Value of N. Note That If 1+n 5, y

The colon operator : is used to iterate through values with an optional step value. For example, 1:5 creates the vector [1 2 3 4 5] and 1:n:5 uses a step of n. The colon operator can also be used to select entire rows or columns from a matrix, such as A(:,4) to select the 4th column. linspace creates a linearly spaced vector between x and y with n number of elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

colon operator is used to iterate through the values x through y with default step value of 1: x:y

e.g: the command


y = 1:5

***note that it is not necessary to use [] to create an array thorugh this method

will create the row vector


[1 2 3 4 5]
y = 1:n:5 will have the step value of n. *note that if 1+n > 5, y = [1]

SELECTION WITH THE COLON OPERATOR


to select an entire column
A(:, 4) will select the 4th column
A(3, :) will select the entire 3rd row

A(x, n) selects xth element to the nth. for rectangular matrices, the indexing is as follows:
A = a1 a4 a7
a2 a5 a8
a3 a6 a9

linspace
syntax: linspace(x,y,n)
create a linearly spaced vector in inclusive range [x,y] with number of elements n:
if n is ommited, the default number of values that will be created is 100.

You might also like