I'm trying to understand a matlab code, but I'm not familiar with matlab much. Can someone please tell me what the meaning of x = [ x[i] ] is?
Thanks in advance.
I'm trying to understand a matlab code, but I'm not familiar with matlab much. Can someone please tell me what the meaning of x = [ x[i] ] is?
Thanks in advance.
Your expression really must be read as
x = [ x [i] ]
Focusing on the right side, you are making a joined matrix (i.e., joining columns) of x along with a 1x1 matrix given by i
(which may be a matrix itself, obviously). Then you are assigning it to another variable, x
in this case.
I must remind you that access to indices is made using round parentheses.
[]
is used to concatenate matrices. e.g.:
a = 3;
b = 2;
c = [a b]
c =
3 2
Your code can be written with spaces to clarify:
x = [x [i]];
i.e. there are two nested uses of the concatenation operator. But doing something like [i]
is pointless; it's equivalent to just i
. i.e. your code is equivalent to:
x = [x i];
i.e. it concatenates x
with i
, and then assigns the result back to x
.