strange Index exceeds matrix dimensions (MATLAB bug?)

1 view (last 30 days)
Hi all,
I have a function running in particular the following code (sI and tdii2 are matrices):
% debugging
class(sI) % double
class(tdii2) % uint32
size(sI) % 512 672
numel(sI) % 344064
min(tdii2(:)) % 1
max(tdii2(:)) % 343988 (not 391863)
save('temp55.mat', 'sI', 'tdii2');
% this line produces an error
imgvals = sI(tdii2);
When I run it, it breaks with
??? Index exceeds matrix dimensions.
Error in ==> backproject_single at 133
imgvals= sI(tdii2);
Even worse, when I execute this
load('temp55.mat', 'sI', 'tdii2');
imgvals= sI(tdii2);
in the console, it works perfectly fine.
I am totally puzzled.... Has anyone an idea what the cause could be?
Thanks Thomas

Answers (1)

Matt Fig
Matt Fig on 6 Jun 2011
If size(sI) is as you say, then indexing into it with values greater than 512*672 = 344064 should indeed cause an error!
max(tdii2(:)) > (512*672) % Returns true using 391863 for L.H.S.
  2 Comments
Thomas
Thomas on 6 Jun 2011
Thanks Matt! Sorry, I mistyped the number, it was below 344064 (3439XX, the XX I don't remember.... )
I cannot reproduce the error now since Matlab keeps crashing with seg violation and bluescreen whenever I run the program.
It is pure matlab code, it does not use .mex files.
So probably there is something seriously wrong. I'll reinstall and keep you updated whether that helps.
Thomas
Thomas on 6 Jun 2011
Update: I reinstalled matlab,... at least the bluescreens are gone now, but the problem remains. (and max(tdii2(:)) = 343988)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!