Matlab-colon (:)

colon (:)

Create vectors, array subscripting, and for loop iterations

DescriptionThe

colon is one of the most useful operators in MATLAB. It can create vectors, subscript arrays, and specify for iterations.
The colon operator uses the following rules to create regularly spaced vectors:

j:k is the same as [j,j+1,...,k]
j:k is empty if j > k
j:i:k is the same as [j,j+i,j+2i, ...,k]
j:i:k is empty if i > 0 and j > k or if i < 0 and j < k

where i, j, and k are all scalars.
Below are the definitions that govern the use of the colon to pick out selected rows, columns, and elements of vectors, matrices, and higher-dimensional arrays:

  • 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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 坐在牛背上的我,总是神错错被震下来 账户里买过的股到处有,为何不能带我一乘 为了股孤军奋斗,早就吃够了亏钱的苦 在...
    严小松阅读 2,732评论 0 0
  • 初级 小明之前完全没接触过Android开发,是个应届生,他的待遇是13k,然后小明以校招的身份进入了名企,然后小...
    小学生写代码阅读 2,790评论 1 0
  • 读书,是提升一个人综合素质的一个最便捷,最实惠的一种方式。但是,为什么还是有那么多的人不喜欢读书,甚至是抗拒读书呢...
    敬先生阅读 3,430评论 0 1
  • 《背诗泰河边》 作者:魏城 在遥远的莎士比亚的故乡 我吟咏着李白杜甫的诗 默念着苏东坡辛稼轩的词 走过狄更斯小说中...
    魏城阅读 1,644评论 0 4