0

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.

4

2 回答 2

3

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.

于 2012-06-09T13:32:04.647 回答
3

[] 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.

于 2012-06-09T13:32:26.770 回答