StackOverflowMATLABchat/legtools

Append method crash when passed non-string input

Closed this issue · 0 comments

sco1 commented

Calling legtools.append with a non-string input is not caught by input validation.

For example:

% Sample data
x = 1:10;
y1 = x;
y2 = x + 1;

% Plot a thing!
figure
plot(x, y1, 'ro');
lh = legend('Circle', 'Location', 'NorthWest');

% Add a thing!
hold on
plot(x, y2, 'bs');
legtools.append(lh, 12)

Throws the following error:

While setting the 'DisplayName' property of 'Line':
Value must be a string.

Error in matlab.graphics.illustration.Legend/setStringImpl

Error in matlab.graphics.illustration.Legend/set.String_I

Error in matlab.graphics.illustration.Legend/set.String

Error in legtools.append (line 58)
            lh.String = newlegendstr;

Error in testcode (line 16)
    legtools.append(lh, 12)