Index exceeds matrix dimensions

1 view (last 30 days)
goyanks1989
goyanks1989 on 19 Jan 2016
Edited: Walter Roberson on 21 Jan 2016
Hello, I am receiving an error at line 74 and was curious why this error is occurring and what I should do to resolve the issue.
Index exceeds matrix dimensions.
Error in NonConvective (line 74)
bigDATA(ii, bigDATAstart:(bigDATAstart - 1 +length(goodPoints))) = a(goodPoints);
  2 Comments
Stephen23
Stephen23 on 19 Jan 2016
Edited: Stephen23 on 19 Jan 2016
@t v: please edit your question, and do all of the following:
  • delete the code from your question. So much code is difficult to read.
  • upload the code by clicking the paperclip button, then both the Choose file and Attach file buttons.
  • Show us all of the error message. This means all of the red text. We need the complete error message because it gives us useful information.
goyanks1989
goyanks1989 on 19 Jan 2016
Thank you, I see how cluttered it appeared in the previous format. I have updated the question.

Sign in to comment.

Answers (1)

jgg
jgg on 19 Jan 2016
Your problem is this:
bigDATA = nan(16, 100000);
This is a 16x100,000 matrix of NaNs.
ii_array = [198 139 81 80 84 238 63 353 43 159 92 62 66 73 6 7 238 239 246 156 140 141 361 362 366];
This is a 1x25 vector, so this length(ii_array) is 25. Therefore:
for ii = 1:length(ii_array)
bigDATA(ii, bigDATAstart:(bigDATAstart - 1 +length(goodPoints))) = a(goodPoints);
%%snip
end
This loop, where you get your error, is looking to store a(goodPoints) into element 17 of a 16x100,000 matrix, which throws the error. You need to either fix your indexing or make your bigData matrix correct. I don't understand your code well enough to tell you which one, but I suggest you need to carefully walk through it to make sure it's working as intended. Try using the keyboard command and walking through your loops.
  2 Comments
goyanks1989
goyanks1989 on 19 Jan 2016
Thank you, that does make sense but I am still getting the same error when I increased bigDATA to fit my variables. The error has something to do with running the code for 2 time periods instead of 1, as my code for 1 time period ran smoothly.
%
utcStarts1 = [48009, 52467, 54128, 54591, 45001, 55587, 56714];
utcEnds1 = [66799, 61999, 59999, 57999, 45002, 74999, 61499];
%
utcStarts2 = [730001, 72001, 74001, 80001, 45003, 82001, 68001];
utcEnds2 = [77659, 80271, 80894, 86181, 74428, 87252, 78116]; %end
where
goodPoints1=(utcStarts1(jj):1:utcEnds1(jj));
goodPoints2=(utcStarts2(jj):1:utcEnds2(jj));
goodPoints=[goodPoints1, goodPoints2];
When I ran the code for just 1 time period, like below, the code ran fine, with no errors.
%
utcStarts = [66800, 62000, 60000, 58000, 44553, 75000, 61500];
utcEnds = [73000, 72000, 74000, 80000, 45000, 82000, 68000];
where
% goodPoints = find((utcTime >= utcStarts(jj)) &( utcTime <utcEnds(jj)))
I feel like I am overlooking something very simple that will fix this. Any more help is appreciated!
jgg
jgg on 20 Jan 2016
You need to post all your code; I can't see what you are doing. I'd suggest trying to debug this by in the editor under breakpoints, click dbstop if error. Then, when your program errors you can check to see what is going on.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!