The logical indices contain a true value outside of the array bounds.

조회 수: 89 (최근 30일)
Hi everyone,
I am trying to do indexing to get the values in order to plot it. My variables:
Temp1 = 7570x1 double;
Temp2 = 7570x1 double;
Index = (TER == 4); % 2030 x 1354 logical
Now for the pixels where value is 4 I need to find the values of Temp1 and Temp2
X = Temp1(Index);
Y = Temp2(Index);
But it gives me error.
The logical indices contain a true value outside of the array bounds.
I guess it's because Index is a matrix and Temp1 and Temp2 are column vectors. Any suggestions how to solve it? Thanks!
  댓글 수: 1
DGM
DGM 2021년 9월 2일
The logical array called "index" contains 2030*1354 = 2748620 elements. The two vectors only contain 7570 elements. Not only are they not the same shape or size, 2748620 isn't even integer-divisible by 7570. There is no obvious correspondence bewteen the arrays at all. Is there supposed to be?

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 2일
The difference between matrix and vector is not causing the problem.
Index = (TER == 4); % 2030 x 1354 logical
Suppose that the very last entry in TER was 4. According to your comment that would be at index (2030, 1354) which would be at offset
2030*1354
ans = 2748620
When Index is then used as a logical index, it would then require that the array being indexed had at least 2748620 elements in it. But you are indexing Temp1 and Temp2, which only have 7570 elements in them.
You would have a problem using Index as an index into Temp1 or Temp2 any time there was a true value beyond offset 7570, which would correspond to row 1480 column 4 in your 2030 x 1354 array.
It is not at all obvious what Temp1 or Temp2 have to do with "pixels" in this situation.

추가 답변 (0개)

카테고리

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