Using uint8 as matrix index

조회 수: 7 (최근 30일)
Salman Gul
Salman Gul 2016년 5월 31일
답변: Image Analyst 2016년 6월 1일
I have a matrix "parent" defined as uint32 type. Later, i use this parent to index another matrix
Counter(parent(2));
But i get the error 'Subscript indices must either be real positive integers or logicals.'
I have defined "Parent" as uint32 to save memory.

채택된 답변

the cyclist
the cyclist 2016년 5월 31일
편집: the cyclist 2016년 5월 31일
This code works perfectly fine for me:
A = uint32([4 5 6]);
idx = uint8(2);
A(idx)
It also works if idx is defined as a uint32.
Maybe you can post a code snippet that illustrates the error you are getting?
  댓글 수: 2
Salman Gul
Salman Gul 2016년 5월 31일
In my case, counter itself is a uint8 type matrix...could that be an issue?
the cyclist
the cyclist 2016년 5월 31일
Shouldn't be a problem. My best guess is that you are accidentally trying to index with a zero, and the memory-saving integer situation is a red herring.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2016년 5월 31일
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 5월 31일
편집: Walter Roberson 2016년 5월 31일
Is your code happening to try to store negative values for the counters? Does it arrive at the counters by doing subtractions that might happen to result in negative values?
Put a conditional breakpoint on the line
dbstop at LINENUMBER if parent(2) == 0
and run again and I suspect you will discover that the value is 0.
the cyclist
the cyclist 2016년 5월 31일
Salman, you now have 3 out of the top 10 contributors on this forum guessing at a solution. Can you please distill the simplest possible version of your code that will display this error, and post it? (Sometimes the distillation process itself will expose the error.)

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2016년 6월 1일
Note: parent and Parent are two different things because MATLAB is case sensitive. In your question you use it both ways and if you do that in your code, you will possibly have a problem. Do a case insensitive search for parent and make sure you're consistent in how you're using the letter case (capitalization).

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by