Info

This question is closed. Reopen it to edit or answer.

Legend doesn't work with subplot in 2014b but same code works in 2010a

1 view (last 30 days)
I have this code that works in 2010a
subplot(2,2,1)
plot(tstore,xstore(:,1))
hold on
plot(t,TAS_model-x0(1),'r')
title('TAS comparison')
xlabel('time-secs')
ylabel('Vel-m/s')
legend('Linear model','Non linear model')
subplot(2,2,2)
plot(tstore,xstore(:,2))
hold on
plot(t,alpha_model-x0(2),'r')
title('Alpha comparison')
xlabel('time-secs')
ylabel('Alpha-Rad')
All variables exist in workspace and plots turn out fine in 2010a. In 2014b i get an error from the legend function that it has a wrong number of inputs.
Any ideas why? I wish the developers had kept backward compatibility in mind.
  1 Comment
dpb
dpb on 26 Dec 2014
Edited: dpb on 27 Dec 2014
I hear ya' on the compatibility issues w/ Matlab...'tis a pain indeed.
However, nothing in the current doc indicates that the above shouldn't work; the only documented change is that legend now returns one of the high-falutin' new "objects" instead of an axes handle, but no mention of function inputs changing.
While it shouldn't be necessary, just for debugging try
hL=plot(tstore,xstore(:,1));
hold on
hL=[hL; plot(t,TAS_model-x0(1),'r')];
legend(hL,'Linear model','Non linear model')
and see if it associates the strings correctly with the line handles.
Either way, I'd submit the original code to official support at www.mathworks.com as a bug in the new graphics engine implementation.
ADDENDUM
Of course, try
clear legend
which legend
to ensure you haven't inadvertently created an aliased version...

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!