Index in position 1 exceeds array bounds (must not exceed 1).
This error is an indexing error, which suggests to me that one or more of your indices in that line of code are wrong. Further, it's not reporting the error from inside the function accumarray, which means the error is happening before anything is actually passed to that function. Based on that, we conclude that the error arises in the arguments you're passing to accumarray.
Since it's indicating that an index in position 1 is wrong, and the only part of that line of code with an index in position 1 that can potentially exceed 1 is velData{i,1} (the index in position 1 exceeds 1 if i>1), that's the obvious candidate. If you do size(velData,1), do you get something greater than 1? If not, that's your problem right there.
Based on my understanding of what you're trying to do, I would think you should get what you're after if you fix that problem. However, you said, "But even if I solve the above error, I doubt whether I will get the intended results. Because accumarray is saying that the data from velData will be devided into bins specified by disc_x." Isn't that what you want? I don't understand why that's a problem.
Essentially, using your strategy here, for file i, each row of expData{i,1} is associated with the same row of velData{i,1} (ignoring the indexing error, anyway). You're then binning the rows of expData{i,1} and velData{i,1} according to the values in the first column of expData{i,1}, with the index of the corresponding bin stored in the vector disc_x{i}. Next, you want to compute the means of the first column of velData{i,1} by bin. If that's what you're after, then your code should do that (again, as long as you fix the above indexing issue first).
2 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/591115-indexing-arrays-of-binned-data#comment_1002598
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/591115-indexing-arrays-of-binned-data#comment_1002598
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/591115-indexing-arrays-of-binned-data#comment_1002631
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/591115-indexing-arrays-of-binned-data#comment_1002631
Sign in to comment.