The logical indices contain a true value outside of the array bounds.
131 views (last 30 days)
Show older comments
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 Comment
DGM
on 2 Sep 2021
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?
Accepted Answer
Walter Roberson
on 2 Sep 2021
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
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!