0

Trying q = density(1:3:end) but not working. Instead, q is being assigned to first, fourth and last element.

Saswata Mishra
  • 95
  • 1
  • 10
  • Please note that 'density' is my 7x1 column vector. – Saswata Mishra Feb 04 '20 at 07:55
  • 1
    Please have a look, how the [`colon`](https://www.mathworks.com/help/matlab/ref/colon.html) operator exactly works. To explicitly select the stated elements, use something like `q = density([1, 3, 6])`. – HansHirse Feb 04 '20 at 08:05
  • Where `end = 7` (because it's a 7 element array), the vector `[1:3:end] = [1, 4, 7] = [1, 1+3, 1+2*3]`. The linked duplicate covers indexing fairly comprehensively, you may also find the [array indexing](https://uk.mathworks.com/help/matlab/math/array-indexing.html) and [creating arrays](https://uk.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html) documentation pages useful. – Wolfie Feb 04 '20 at 08:38

0 Answers0