I got an error Index exceeds matrix dimensions.

When I ran this script I'm getting an error which I indicated below. Is there someone could help me please?

3 Comments

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.
For versions 16b+, you could simply write,
alfa = reshape(hh./(2*b.'),1,[]);
I've got 2016a :/

Sign in to comment.

Answers (3)

ME
ME on 11 Dec 2017
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?
Guillaume
Guillaume on 11 Dec 2017
Edited: Guillaume on 11 Dec 2017
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!
Thanks for answers, I fixed it by attaching one more hh matrix.

Asked:

on 11 Dec 2017

Answered:

on 11 Dec 2017

Community Treasure Hunt

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

Start Hunting!