Subindex error when using with graphics

2 Ansichten (letzte 30 Tage)
Ziv Kassner
Ziv Kassner am 10 Jan. 2018
Kommentiert: Ziv Kassner am 10 Jan. 2018
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Jan. 2018
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.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by