1

I am trying to break down an array of the size 1x117031 (X array) to an array of size Nx140 (Y array) so I can plot the new array and find out how the plots changed during the cyclic tests (N to be around 1000).

Here is my code:

mydata=xlsread('average_4_5');

for i=100:size(mydata)
    X(i-99)=mydata(i,10);
end

for j=1:1000
    Y(j, 1:140)=X(1,((140*j)-140):140*j);
end

But I get an error:

Subscript indices must either be real positive integers or logicals.

It seems the problem is coming from the X(1,((140*j)-140):140*j) and I don't have any idea why this doesn't recognise j as being an integer value.

Any thoughts on how I can do this transformation and plot the rows of Y to give me a graph with 1000 entries?

Dan
  • 45,079
  • 17
  • 88
  • 157
Kamran
  • 75
  • 7
  • 2
    I not sure I followed exactly what you wanted to do, but it sounds like you could very likely drop all your loops and just use the [`reshape`](http://www.mathworks.com/help/matlab/ref/reshape.html) function. – Dan Mar 23 '16 at 12:20
  • 1
    @Dan Thank you for your comment. Exactly, I replaced mine now with a reshape function and it works. Thanks for reminding me of that – Kamran Mar 23 '16 at 12:23
  • It is best [not to use `i` and `j` as variables names in Matlab](http://stackoverflow.com/q/14790740/1714410). – Shai Mar 23 '16 at 12:27

1 Answers1

3

((140*j)-140) is 0 when j is 1. The problem is not that j is not an integer but that you can't index a matrix with 0. So the keyword here is not integer but positive.

However the built-in function reshape should solve this for you.

Dan
  • 45,079
  • 17
  • 88
  • 157