You can use the colon operator to create a vector of indices to select rows, columns or elements of arrays.
The following table describes its use for this purpose (let us have a matrix A):
A(:,j) - is the jth column of A.
A(i,:) - is the ith row of A.
A(:,:) - is the equivalent two-dimensional array. For matrices this is the same as A.
A(j:k) - is A(j), A(j+1),...,A(k).
A(:,j:k) - is A(:,j), A(:,j+1),...,A(:,k).
A(:,:,k) - is the kth page of three-dimensional array A.
A(i,j,k,:) - is a vector in four-dimensional array A. The vector includes A(i,j,k,1), A(i,j,k,2), A(i,j,k,3), and so on.
A(:) - is all the elements of A, regarded as a single column. On the left side of an assignment statement, A(:) fills A, preserving its shape from before. In this case, the right side must contain the same number of elements as A.
No comments:
Post a Comment