MATLAB: copy a specific portion of an array

前端 未结 2 649
梦如初夏
梦如初夏 2021-01-20 01:14

I am trying to copy a few elements from a matrix, but not a whole row, and not a single element.

For example, in the following matrix:

a = 1 2
    3          


        
相关标签:
2条回答
  • 2021-01-20 01:38

    Elements in a matrix in MATLAB are stored in column-major order. Which means, you could even use a single index and say:

    b = a(1:3);
    

    Since the first 3 elements ARE 1,3,5. Similarly, a(6) is 2, a(7) is 4 etc. Look at the sub2ind method to understand more:

    http://www.mathworks.com/help/techdoc/ref/sub2ind.html

    0 讨论(0)
  • 2021-01-20 01:54

    You are not "removing" the second column, you are referencing the other column.

    You should read some of the Matlab docs, they provide some help about the syntax for accessing portions of matrices:

    http://www.mathworks.com/help/techdoc/learn_matlab/f2-12841.html#f2-428

    0 讨论(0)
提交回复
热议问题