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
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.
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()
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?
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.
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.
"Andy " <theori...@gmail.com> wrote in message <hhg777$4t0$1...@fred.mathworks.com>...
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>...
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.