0

Why this portion of code is still showing me an error of kind Subscript indices must either be real positive integers or logicals the indices are uint8 so real positive integers ???

    t = uint8( t_lbls(i) );
    te = uint8( test_lbls(e) ); 
    mat2conf(t,te) = mat2conf( t,te )+ 1;
  • 1
    possible duplicate of [Subscript indices must either be real positive integers or logicals, generic solution](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) – Robert Seifert Apr 15 '14 at 15:17
  • I saw that, it did not solve my problem –  Apr 15 '14 at 20:09
  • At the request of @thewaywewalk I have made the point more clear that 0 is also not a valid index value. – Dennis Jaheruddin May 26 '14 at 15:41

1 Answers1

0

I suspect that you may have indices that are 0. Try offsetting by 1. You will also need to cast to double because if you add 1 to 255, you will not get 256. It will cap off to 255 as you have casted your arrays to uint8. The purpose of you casting to uint8 is unclear to me, but I will assume that this step is necessary. As such, you simply have to add the following two lines.

t = uint8( t_lbls(i) );
te = uint8( test_lbls(e) ); 
t = double(t) + 1; % Cast and offset t
te = double(te) + 1; % Cast and offset te
mat2conf(t,te) = mat2conf( t,te )+ 1;
rayryeng
  • 102,964
  • 22
  • 184
  • 193