I am having trouble finding the source of an indexing error

I am dealing with some large arrays and I keep getting the error: “Indices must be real positive integers or logical” or “Index exceeds size.” The vector of indices is created through the function ALLCOMB. The inputs to ALLCOMB are vectors of positive integers, so the output should be a matrix of positive integers. I have been able to find the location of the offending index on several occasions and it turns out to be a 6+eps or a 9+eps rather than a 6 or a 9. The truly puzzling part though, is that I cannot change these values in my vector. While in debugging mode, I have tried to round the vector, change the data type to int8 or uint8, and I have even manually typed in the correct integer values, but to no avail. I will type in A(1,7819)=9, then check the value before moving on, and it is still 9+eps.
Also, when I get the error “Index exceeds size,” I will view the max and min of my vector of indices to find that they are in fact well within the size of the referenced array.
I am also getting “out of memory” errors on programs that have successfully run only minutes before. I increased the Java Heap size, but with no effect.
I am starting to suspect an issue with my system, any suggestions? I’ll list my system specs below:
Machine: iMac 21.5-inch Mid 2011 Processor: 2.8 GHz Intel Core i7 Operating system: OS X 10.8.3 Memory: 32 GB DDR3 Storage: 251 GB Flash with 172GB free and a 2TB SATA (MATLAB installed on Flash)

Answers (1)

Well we can't do much without seeing any code. But I'd say that if you cast the indexes, "A", to integers and it's still saying that, then you must have 0 or negative numbers, or a positive number greater than numel of whatever array you're trying to use "A" as indices for, or greater in one of the dimensions. Of course if you really cast to int32, then no number is going to be an integer plus eps. 32 gigabytes of RAM is impressive and should handle most MATLAB programs. Tell me this:
size(theArray) % The size of the array A will be used as indices for.
minA = min(A(:)) % No semicolon so it will print to the command window.
maxA = max(A(:)) % No semicolon so it will print to the command window.

5 Comments

Hi Image Analyst, thanks for the response, I'll list my code below and I'll show you the array characteristics while in DB mode. As you can see, the indices all exist between 1 and the max of the referenced array. The problem is that some of the elements in the indexing vector come out as 'value'+eps. I will show you how I have tried to manually change these elements to integers, but am not able.
Here is my Code:
***************************************************************
function [ K3 ] = PossibleTrades4( IP,B ) % This function produces all possible combinations of choices by % individuals in IP over the decisions in B
[sip,~]=size(IP);
[sb,~]=size(B);
for i=1:sb
d{i}=[-1,1]; %#ok<AGROW>
end
K=allcomb(d{1:sb});
sk=sum(K,2);
K(sk==-1*sb,:)=[];
[lk,~]=size(K);
for i=1:sip
h{i}=1:lk; %#ok<AGROW>
end
K2=allcomb(h{1:sip});
K3=zeros(lk^sip,sip*sb);
for i=1:sip
try
A=K2(:,i);
K3(:,i*sb-sb+1:i*sb)=K(A,:);
catch err
if (strcmp(err.identifier,'MATLAB:badsubscript'))
warning('POSSTRADE4:IndexError',...
'An index problem has occurred, stopped in DB mode')
dbstop
else rethrow(err);
dbstop %#ok<UNRCH>
end
end
end
end
************************************************
Here are the array characteristics:
************************************************
EDU>> [K3]=PossibleTrades4(IP1,B1);
Warning: An index problem has occurred, stopped in DB mode
> In PossibleTrades4 at 26
28 dbstop
K>> K(A,:);
??? Subscript indices must either be real positive integers or logicals.
K>> size(K)
ans =
15 4
K>> MinA=min(A)
MinA =
1
K>> MaxA=max(A)
MaxA =
15
*************************************************
I went through A to find the offending element. Here are my attempts to change that element to an integer. It does not work.
*************************************************
K>> K(A,:);
??? Subscript indices must either be real positive integers or logicals.
K>> K(round(A),:);
??? Subscript indices must either be real positive integers or logicals.
A(155875328)
ans =
14.0000
K>> A(155875328)=round(A(155875328));
K>> A(155875328)
ans =
14.0000
K>> ans-14
ans =
2.8422e-14
K>> A(155875328)=14;
K>> A(155875328)
ans =
14.0000
K>> ans-14
ans =
2.8422e-14
***************************************************
Isn't that odd? I manually type in '14' for the element in A, yet it remains 14+eps. Could this result from some sort of kernel panic that has somehow gone undetected? Directly before this problem started occurring, I had a legitimate memory shortage for a large operation which crashed matlab, and later I had a power outage while running a program.
K>> whos A
Name Size Bytes Class Attributes
A 170859375x1 1366875000 double
My gosh - why is A so huge? Why do you need indexes that go as high as 170 million? I've never had an index go that high.
Well, the indices only range from 1-15, but are stacked in specific sequences for a total of 170 mil rows. The program is meant to enumerate all of the possible combinations of m binary decisions made by n agents, less some logical discrepancies. I am working on an algorithm that avoids such enumeration, but for a proof of concept, I need to compare that algorithm to the fully explicit case where all combinations are used.

Sign in to comment.

Asked:

on 27 May 2013

Community Treasure Hunt

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

Start Hunting!