question about addressing matrix elements

In the 4th line in the code below, I am having difficulty understanding what the -1 is doing. Is that a -1 step size?
Thanks, Chris
G0=zeros(m/2,n);
G0(:,1:2:n)=bay(1:2:m,1:2:n); %bay is a 192x128 double matrix
hh1 = [0 0.5 1 0.5 0];
xx1 = [G0(:,3:-1:2), G0, G0(:,n-1:-1:n-B)];
f1 = conv2(1,hh1,xx1,'valid');

Answers (1)

James Tursa
James Tursa on 18 Feb 2015
Edited: James Tursa on 18 Feb 2015
Yes. The colon operator when used with three values is
starting_value:step:ending_value
e.g.,
5:-1:2
ans =
5 4 3 2
So, the expression
G0(:,3:-1:2)
means "all the rows" and "columns 3 and 2 in that order". I.e., the 3rd and 2nd columns of G0.

Asked:

on 18 Feb 2015

Edited:

on 18 Feb 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!