Index in position 1 exceeds array bounds (must not exceed 1).
30 views (last 30 days)
Rohit Mangalekar on 21 Sep 2021
Hello, I went through the other queries under the same error. I got the what it means, but still dont understand in my case why does it show up.
Does it have any other reason or I am still making the same mistake. Could anybody please check the following code and help me?
%Some code earlier which produces the arrays WCM, WBM, KSM, OTM, BTM, WMM. These array are converted to the matrix of size 10 X 86400.
% But in Input file- if any of the input variables (WC,WB,KS,WM,BT,OT) are absent then the corresponding variables i.e. WCM, WBM etc.are set to zero.
% NumWC, NumWB etc. are set to by default valu of 1.
% When any I input the file with First four variables (WC,WB,BT,KS), there is no problem. I get the value of All.
% But when I input the file with only two variables (WC and WB) or with only one variable (WC), I get the error "Index in position 1 exceeds array bounds (must not exceed 1)."
All the variables (WCM,WBM...etc) are supposed to be of size 10 x 86400. and NumWC, NumWB.... etc are scalar values.
When I have only WC or WC and WB as my input variables, I get the error. Could you help me knowing what I am missing?
Harikrishnan Balachandran Nair on 24 Sep 2021
Edited: Harikrishnan Balachandran Nair on 24 Sep 2021
I understand that you are encountering an error which says " index in position 1 exceeds array bounds" , on running your code.
In the code that you have provided, you have set your input variable to '0' incase it is an empty array. This sets the input to a 1*1 double array. When you try to access the 'ith' row in the corresponding input, you will face an indexing error, when i is greater than 1.
You can resolve this issue by using the 'zeros' function in matlab to initialize the input as a 10*86400 array of zeros, which is the dimension that you are expecting. You may refer to the following line of code.