The logical indices contain a true value outside of the array bounds.
134 次查看(过去 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
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
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!