I got an error Index exceeds matrix dimensions.
Show older comments


When I ran this script I'm getting an error which I indicated below. Is there someone could help me please?
3 Comments
Adam
on 11 Dec 2017
Use the 'Stop on errors' (< R2017b) or 'Pause on errors' (R2017b) option from the breakpoints menu and it will stop at the point of the error. Then just look at the sizes of the relevant objects and the indices you are passing to them and it should become obvious.
Nothing stands out to me from glancing over the code.
KL
on 11 Dec 2017
For versions 16b+, you could simply write,
alfa = reshape(hh./(2*b.'),1,[]);
Berk B
on 11 Dec 2017
Answers (3)
ME
on 11 Dec 2017
0 votes
I have just run the code exactly as given in your problem description and it works absolutely fine for me using R2016a.
It appears as though the code segment you present in your problem description is part of a longer code (hence the issue being at line 88). Have you tried running this segment in isolation to see if it produces the same issue?
I'm not sure which font you're using in your editor/command window but your l (letter el) and your 1 (number 1) look exactly the same, so could it be possible that one of the 1 in the alfa(1,s)=hh(1,i)/(2*b(l,j)) is actually an l and that the l variable does exist (with value > 11)
In any case, as pointed out by KL using a loop for that sort of calculation is a waste of time
alfa = reshape(hh./(2*b.'),1,[]); %R2016b or later
alfa = reshape(bsxfun(@rdivide, hh, 2*b.'), 1, []); %any version
Personally, I would not bother with the reshape and keep alfa as a 11x11 matrix.
I would also recommend switching your UI to a font where 1 and l look clearly different!
Berk B
on 11 Dec 2017
0 votes
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!