Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

??? Attempted to access e(1,0); index must be a positive integer or logical.

108 views
Skip to first unread message

burcu

unread,
Dec 30, 2009, 1:10:20 PM12/30/09
to
Dear all,

I'm working on an hmm issue. I'll run hmmtrain command which looks like:
>> [EMSTTR, ESTEMIS]=hmmtrain(seq,trans,emis);
and i get the error:
??? Attempted to access e(1,0); index must be a positive integer or logical.

Error in ==> hmmdecode at 146
fs(state,count) = e(state,seq(count)) .* (sum(fs(:,count-1) .*tr(:,state)));

Error in ==> hmmtrain at 239
[p,logPseq,fs,bs,scale] = hmmdecode(seq,guessTR,guessE);


The problem is with my data in seq. A row of my data in seq is looks like:

0,1,1,70,181,5450,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,8,8,0.00,0.00,0.00,0.00,1.00,0.00,0.00,9,9,1.00,0.00,0.11,0.00,0.00,0.00,0.00,0.00,138

As it's also including some non integer values, i've tried to round the matrix also and obtain an only integer matrix, but the problem remains.
Is there any idea about this problem?

Thanks
Burcu

Andy

unread,
Dec 30, 2009, 1:22:04 PM12/30/09
to
"burcu " <burc...@hotmail.com> wrote in message <hhg52b$jss$1...@fred.mathworks.com>...

I can't tell how you think the code should treat this scenario. You could solve the problem by adding 1 to all elements of seq, but that's unlikely to be the desired result. A more reasonable guess would be to replace seq by seq(seq>0) to ignore the 0. But again, I can't tell if this is the desired result. Should seq not have any noninteger or 0 values to begin with? You need to answer these sorts of questions so we know how to change the code appropriately.

Matt J

unread,
Dec 30, 2009, 1:22:04 PM12/30/09
to
"burcu " <burc...@hotmail.com> wrote in message <hhg52b$jss$1...@fred.mathworks.com>...
=====

Why are you trying to use non-integer indices when you know these locations in your array don't exist????

My guess is you want to use interp1()

burcu

unread,
Dec 30, 2009, 1:36:04 PM12/30/09
to
Hi Andy,

This code is supposed to be a recognition code. Every column of my input data is a feature vector and last column indicates the class of the sequence.
So adding 1 to all the elements might cause some mistakes in my results.
All of my elements are no integers, there are some values like 0.1, 0.9 etc. and also 0s are the meaningful data for me. seq(seq>0) wouldn't work also.

If i round all the values, i checked the results and there were no noninteger values but i'm taking the same error.

I tried to create a random seq data just for trial and i create an integer matrix manually, it worked. So i couldnt understand what is wrong with this data.
Could my delimiters, commas causing this?

Andy

unread,
Dec 30, 2009, 1:47:03 PM12/30/09
to
> So i couldnt understand what is wrong with this data.

The problem is that seq contains zeroes. In the line:

e(state,seq(count))

if seq(count)=0, then e(state,0) doesn't make any sense, and returns an error. What do you want the behavior to be in this situation? Your code not appear syntactically incorrect. You're just not doing anything to make sure that the data contained in seq is a valid reference index for the array e.

Matt J

unread,
Dec 30, 2009, 1:55:05 PM12/30/09
to
"burcu " <burc...@hotmail.com> wrote in message <hhg6ik$o4m$1...@fred.mathworks.com>...

> Hi Andy,
>
> This code is supposed to be a recognition code. Every column of my input data is a feature vector and last column indicates the class of the sequence.
> So adding 1 to all the elements might cause some mistakes in my results.
> All of my elements are no integers, there are some values like 0.1, 0.9 etc. and also 0s are the meaningful data for me. seq(seq>0) wouldn't work also.
>
> If i round all the values, i checked the results and there were no noninteger values but i'm taking the same error.
>
> I tried to create a random seq data just for trial and i create an integer matrix manually, it worked. So i couldnt understand what is wrong with this data.


Perhaps the following example will help. Can you see why certain indexing produces errors? It's because MATLAB indices must be integers between 1 and length(v).

>> v=[7.4 3.8 2.1]

v =

7.4000 3.8000 2.1000

>> v(0)
??? Subscript indices must either be real positive integers or logicals.

>> v(1)

ans =

7.4000

>> v(2)

ans =

3.8000

>> v(3)

ans =

2.1000

>> v(4)
??? Index exceeds matrix dimensions.


So as you see, 0 is not a valid index in MATLAB. You have to figure out which indices >=1 and less than the size of the array that your seq=0 values should correspond to. That rule, however, is something only you can know.

burcu

unread,
Dec 30, 2009, 2:37:04 PM12/30/09
to
So to get rid of zeros, i've added 1s to every element and than round them all. so i have a totally positive integer elements but error still exists. Sorry if i understand wrong what you meant.

"Andy " <theori...@gmail.com> wrote in message <hhg777$4t0$1...@fred.mathworks.com>...

Andy

unread,
Dec 30, 2009, 2:43:04 PM12/30/09
to
Could you post your changes to the code and the resulting error?

burcu

unread,
Dec 30, 2009, 2:54:04 PM12/30/09
to
I've created a matrix of ones with ones comment and sum it with my seq matrix and name it as B. Then round it,
>> B=round(B);
>> [EMSTTR, ESTEMIS]=hmmtrain(B,trans,emis);
??? Attempted to access e(1,5451); index out of bounds because size(e)=[2,848].

Error in ==> hmmdecode at 146
fs(state,count) = e(state,seq(count)) .* (sum(fs(:,count-1) .*tr(:,state)));

Error in ==> hmmtrain at 239
[p,logPseq,fs,bs,scale] = hmmdecode(seq,guessTR,guessE);

This is a different error than the other, sorry i didn't attend it.


"Andy " <theori...@gmail.com> wrote in message <hhgag8$1ur$1...@fred.mathworks.com>...

Andy

unread,
Dec 30, 2009, 3:16:21 PM12/30/09
to
"burcu " <burc...@hotmail.com> wrote in message <hhgb4s$cc0$1...@fred.mathworks.com>...

I think you should invest some time in reading your error messages. It would save a lot of time waiting for a response from the newsgroup community. This error is pretty clear:

??? Attempted to access e(1,5451); index out of bounds because size(e)=[2,848]

At some point during execution, state evaluated to 1, and seq(count) evaluated to 5451. But since size(e)=[2,848], there is no element in row 1, column 5451. So when you tried to access this element, there was an error. This is exactly the same problem you had with the zeros before. You are doing nothing to make sure that the data stored in seq is a valid index for the array e. As a result, you are attempting to access parts of the array e that are not there, which is precisely what the error says.

0 new messages