Simple legend function no longer works in R2014B

13 views (last 30 days)
I just updated to R2014b. I have a simple line as follows in many of my plotting scripts, and none of them works anymore.
For example, if I plot two curves and want to label one as 'A' and one as 'B', I use the following line after the plots:
legend('A', 'B')
This used to work, but after updating Matlab, I get the following error in every script:
Error using legend (line XXX)
Too many input arguments.
Has anyone else had this problem? What do I have to change?
Thanks.

Accepted Answer

Sean de Wolski
Sean de Wolski on 15 Oct 2014
Sounds like a shadowed file. What is the full text of the error message?
Run the following:
dbstop if error
This will stop on the offending line when the error occurs. Once on this line, run:
which -all whatever_functions_are_there
On all of the functions. More than likely one of them is yours that has been accidentally added to the path.
  5 Comments
Sue McMeekin
Sue McMeekin on 17 Oct 2014
I get the same thing you do when I type "which legend -all" so I'll call Tech Support. Thanks for your help.
Sue
Star Strider
Star Strider on 17 Oct 2014
Good luck!
Post the solution here as well when you get this problem resolved.

Sign in to comment.

More Answers (2)

Sue McMeekin
Sue McMeekin on 20 Oct 2014
I believe Sean was correct about the shadowed file. I contacted Tech Support, and they also believed that to be the problem. They told me the following:
*"The typical cause of such an issue is the original function being shadowed by another function with the same name. However, based on the discussion on your post and the tests such as executing "which -all legend" that you conducted, it seems that function shadowing is not the reason.
Now, the implementation of "legend" has changed significantly as of MATLAB R2014b. Also, in a comment on your post, you mentioned that R2012b was not uninstalled. In light of this, one possible reason for this issue to occur might be that the path has not been set correctly for the new installation and parts of the path might still point towards the directory location where R2012b is installed. To see if this is the issue, please execute the following commands:
1) Restore the path and rehash the toolbox cache using the following commands
>> restoredefaultpath
>> rehash toolboxcache
This will make sure that MATLAB search path is set correctly for the R2014b release. Please note that executing these two commands will reset the search path and any custom functions or scripts that you have added to the search path manually during your previous use will have to be added to the path again.
2) After you execute these commands, test your "SimplePlot.m" script again and see if it works. If the script executes as expected and does not throw an error, execute the following command at the MATLAB command prompt.
>> savepath
If the issue is not resolved, close and reopen the MATLAB session and then try the following steps:
1) Find the MATLAB preferences directory location by executing
>> prefdir
2) Open Windows Explorer and navigate to the folder location output by "prefdir". Rename the folder to something else, and then restart MATLAB. For example, the output of "prefdir" would look something like:
C:\Users\......\MATLAB\R2014b
Rename the folder "R2014b" to something else like "myR2014b". Next close the existing session of MATLAB and start a new one.
This process will regenerate the preferences directory that stores the state of your latest MATLAB session."
So I tried all of the above, and then re-ran SimplePlot.m. I still got the error. So I decided to limit my search path to just that script and no other. Then everything worked fine.
I added back into the search path all of my Matlab folders, one by one, and re-ran SimplePlot.m each time. It ran just fine until I added in an old set of scripts that I got from the File Exchange - Electromagnetic Waves & Antennas (EWA) Toolbox by Sophocles Orfanidis. (He has since posted newer scripts that don't cause any problems.)
Once I got rid of the older EWA scripts, the problem has not recurred.
Thanks for everyone's help, including Aniruddha Katre at Tech Support.
Sue

zerof zhou
zerof zhou on 30 Mar 2016
thank you! I come across the same question with you and pick up your help!

Tags

Community Treasure Hunt

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

Start Hunting!