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\...
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