# The selection of columns in the matrix

**URL:** <https://discourse.mc-stan.org/t/the-selection-of-columns-in-the-matrix/16342>\
**Category:** General\
**Tags:** specification\
**Created:** [July 2, 2020, 7:55am UTC](https://discourse.mc-stan.org/t/the-selection-of-columns-in-the-matrix/16342 "2020-07-02T07:55:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodi321](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/xiaodi321/32/9386_2.png) [@xiaodi321](https://discourse.mc-stan.org/u/xiaodi321)\
**Post date:** [July 2, 2020, 7:55am UTC](https://discourse.mc-stan.org/t/the-selection-of-columns-in-the-matrix/16342/1 "2020-07-02T07:55:14Z")

</div>

Now I have a matrix B (p\*k), different columns of the matrix are involved in each calculation.For example, the first column of the matrix is used for the first computation, and the kth column of the matrix is used for the k th computation.So how do I call each time I use it, and how do I define B in Stan to facilitate the calculation

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [July 2, 2020, 8:16am UTC](https://discourse.mc-stan.org/t/the-selection-of-columns-in-the-matrix/16342/2 "2020-07-02T08:16:18Z")

</div>

I’m not sure what you’re trying to do but you can access the columns like this

```stan
matrix[p,k] B;
B[:,1] = rep_vector(1.0, p); // set first column
vector[p] last_column = B[:,k]; // get column number `k`

```
