0

I have an array -

x = [1,2,3,4,5,...,120]

I want to access elements,

 x(9),...,x(15) 

and every 24th element thereafter.

E.G

   x(9),..., x(15) , x(33),...,x(39) , x(57),...,x(63)

and so on, up to

x(120).

Any other element Id like to be 0, so that its looks something like this.

x = [0,0,...,0,0,x(9),...,x(15),0,0,...,0,0,x(33),...,x(39),0,0,...]

If there is a way to do this could I be given some help for a solution?

Jack
  • 105
  • 1
  • 10
  • [Related](https://stackoverflow.com/questions/39429966/create-an-index-vector-based-on-start-and-stop-values/39434045#39434045) – rahnema1 Oct 24 '17 at 17:21

1 Answers1

0

You can create an array of zeros and using a loop change its elements:

result = zeros(size(x));
for k =9:24:numel(x)
    result(k:k+6)=x(k:k+6);
end
rahnema1
  • 15,264
  • 3
  • 15
  • 27
  • Thank you for the reply, but I also wanted the elements in-between too. So `x(9),x(10),x(11),x(12),x(13),x(14),x(15)`. – Jack Oct 24 '17 at 17:12