Subindex error when using with graphics
1 次查看(过去 30 天)
显示 更早的评论
When I run this:
ind = findobj(dig_data.objects.left_wing.points);
non_zero_handles = dig_data.objects.left_wing.points(ind);
I get an error: Function 'subsindex' is not defined for values of class 'matlab.graphics.chart.primitive.Line'.
Where 'dig_data' is a struct and 'points' is a line, and I run the code with matlab 2017 and the code itself was written for matlab older than 2014.
Thank you, Ziv
0 个评论
采纳的回答
Walter Roberson
2018-1-10
That code was always incorrect.
Starting in R2014b, findobj() returns handle objects rather than graphic handles that are represented by doubles that were used before. Your code attempts to use those handle objects as an index into an array, and the error message is telling you that those kinds of objects cannot be used as indices.
When graphics objects were represented by doubles, then only figure handles could be integers, with line objects always having a non-zero fraction. Therefore the doubles that represented line objects were never valid indices in those earlier releases.
The code would have made sense before if it had been
ind = find(dig_data.objects.left_wing.points);
non_zero_handles = dig_data.objects.left_wing.points(ind);
in which case it would have been suitable for the case where some items in the points array were stored as 0 as placeholders representing non-existent lines and the code wanted to extract just the used items.
Assuming that someone might have assigned directly to indices in the points vector, leaving 0's for the unused slots in earlier MATLAB and leaving placeholder objects in current releases, then the current code would be
ind = isvalid(dig_data.objects.left_wing.points);
non_zero_handles = dig_data.objects.left_wing.points(ind);
and both versions would work (under those assumptions) with
ind = ishandle(dig_data.objects.left_wing.points);
non_zero_handles = dig_data.objects.left_wing.points(ind);
if I recall correctly.
Using ishandle() will not work correctly for the case where the points vector contains some objects that were initialized but the objects were deleted.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!