Why do I get an error when using the "legend" function with multiple outputs in MATLAB R2026a?

I want to create a legend for my figure by running the "legend" function with multiple outputs as follows:
>> [leg,labelhandles,outH,outM] = legend('d', 'g');
I encountered the following error:
Warning: Error updating Legend.
The reference object is invalid.
Is this error expected?

 Accepted Answer

Yes, the error is expected. The "legend" function no longer supports returning multiple outputs. Instead, it can return a single "legend" object as follows:
>> legend_object = legend('data_1','data_2',...'data_n')
If you wish to access the properties of a legend e.g. the string names associated with the legend object, please use the following dot notation:
>> legend_object.String

More Answers (0)

Products

Release

R2026a

Community Treasure Hunt

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

Start Hunting!