Index in position 1 exceeds array bounds (must not exceed 1).
Show older comments
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.
if isempty(WCM)
WCM=0;
end
if isempty(WBM)
WBM=0;
end
if isempty(KSM)
KSM=0;
end
if isempty(BTM)
BTM=0;
end
if isempty(OTM)
OTM=0;
end
if isempty(WMM)
WMM=0;
end
for i=1:10
All(i,:)=NumWC.*WCM(i,:)+NumWB.*WBM(i,:)+NumKS.*KSM(i,:)+NumBT.*BTM(i,:)+NumOT.*OTM+NumWM.*WMM;
end
% 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?
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!