Why do I get an error updating legend in Matlab 2017b?
Mostra commenti meno recenti
I try to make a simple legend using the following code:
figure;
myLine = plot(1:10, 'DisplayName', 'This is a straight line');
legend(myLine)
And I receive this error:
Warning: Error updating Legend.
Not enough input arguments.
Also, the legend looks weird (see attached image). I have tried many different input arguments to the legend function, and I have copy pasted examples from the legend documentation, and everything throws the same error.
Any help would be appreciated.

10 Commenti
Eivind Hennestad
il 15 Dic 2017
Amy
il 18 Dic 2017
I don't run into any errors executing the example code you've shared, and the legend that gets created looks normal for me.
Could you possibly share the output from the following command:
which -all legend
Eivind Hennestad
il 19 Dic 2017
Modificato: Eivind Hennestad
il 19 Dic 2017
Eivind Hennestad
il 19 Dic 2017
Amy
il 19 Dic 2017
That's possible - could you try executing the following commands:
restoredefaultpath
rehash toolboxcache
and then see if calling 'legend' works as expected. If it does (and if it is not an issue for you to restore the default path), then also execute the command:
savepath
Eivind Hennestad
il 4 Gen 2018
DW
il 8 Mag 2018
I have the same problem for my Matlab 2018a. Have you found out a permanent fix? Thx.
Eivind Hennestad
il 11 Mag 2018
Modificato: Eivind Hennestad
il 11 Mag 2018
Eivind Hennestad
il 11 Mag 2018
Edoardo Della Santa
il 4 Ott 2018
Hi everyone i still get the warning message even if i remove the narginchk function what am i suppose to do? can anyone help me?
Risposta accettata
Più risposte (3)
Andrew Taylor
il 18 Gen 2018
4 voti
Wanted to update this with something I noticed.
I played around with my startup.m file and the toolboxes I had on the search path. I found that if I ran the suggested fix above, I could add all of my toolboxes back except for CVX, found below, and the legend would display properly.
It looks like they still have some bugs when working with 2017a and later. Hopefully this is just a temporary solution, I'd hope this gets resolved as CVX gets updated.
2 Commenti
Eivind Hennestad
il 11 Mag 2018
Modificato: Eivind Hennestad
il 11 Mag 2018
Eivind Hennestad
il 11 Mag 2018
Konstantinos Poulios
il 6 Nov 2018
2 voti
Hi all.
I'll add another update to the accepted answer that does not require you to remove the cvx installation.
I was getting the same error on my installation ( R2018a ) when I added cvx ( Version 2.1, Build 1123 (cff5298) ) in matlab's path.
My workaround is to open the Set Path option window in matlab, select all the cvx folders and subfolders present in MATLAB search path list, press the Move to Bottom button and then hit the Save button.
This seems to resolve the issue (no more warnings/errors in the console and the legend of the plot), probably due to some matlab inherent priority classification for the paths.
In this way you can still keep the cvx installation and have the legend function work nicely automatically every time you start matlab.
You only get a warning on the console every time matlab starts that prints:
"Warning: Function narginchk has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict."
Hope this is helpful.
1 Commento
zahra sohrabi
il 21 Set 2020
Hi, thank you very much. I don't have cvx toolbox but this way solved my problem
Georgios Emmanouil Stavropoulos
il 19 Nov 2018
0 voti
I don't have cvx (or at least I can't find it), but I have the same problem for a few weeks. Any ideas?
1 Commento
Anik Kumar Samanta
il 30 Nov 2018
You might have some other toolbox which uses CVX. Select default in 'set path' and start adding individual toolbox or paths to check whether the problem exists.
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!