Why do I get an error updating legend in Matlab 2017b?

조회 수: 30 (최근 30일)
Eivind Hennestad
Eivind Hennestad 2017년 12월 15일
댓글: zahra sohrabi 2020년 9월 21일
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
Eivind Hennestad
Eivind Hennestad 2018년 5월 11일
A better option would be to add CVX but remove CVX' own narginchk function:
addpath(genpath('CUSTOMPATH/cvx'))
rmpath('CUSTOMPATH/cvx/lib/narginchk_:')
Note: I do not know if this will interfere with cvx in any way.
PS: I submitted a bug report to cvx about this.
Edoardo Della Santa
Edoardo Della Santa 2018년 10월 4일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Eivind Hennestad
Eivind Hennestad 2018년 5월 11일
편집: Eivind Hennestad 2018년 5월 11일
This seems to happen when adding CVX ( http://cvxr.com/cvx/download/ ) to the matlabpath.
A possible fix:
addpath(genpath('CUSTOMPATH/cvx'))
rmpath('CUSTOMPATH/cvx/lib/narginchk_:')
Note: I do not know if this will interfere with cvx in any way.
PS: I submitted a bug report to cvx about this.

추가 답변 (3개)

Andrew Taylor
Andrew Taylor 2018년 1월 18일
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
Eivind Hennestad
Eivind Hennestad 2018년 5월 11일
편집: Eivind Hennestad 2018년 5월 11일
Yes, I found the same thing. So this is not a bug in Matlab, it is rather caused when adding cvx to the matlabpath.
Eivind Hennestad
Eivind Hennestad 2018년 5월 11일
The problem is that cvx has its own narginchk function, and when this is added to the path it overrides the matlab narginchk and causes problems in the updating of legend. A possible solution would be to add cvx but not their narginchk:
addpath(genpath('CUSTOMPATH/cvx'))
rmpath('CUSTOMPATH/cvx/lib/narginchk_:')
Note: I dont know if this will interfere with cause problems within cvx.

댓글을 달려면 로그인하십시오.


Konstantinos Poulios
Konstantinos Poulios 2018년 11월 6일
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
zahra sohrabi
zahra sohrabi 2020년 9월 21일
Hi, thank you very much. I don't have cvx toolbox but this way solved my problem

댓글을 달려면 로그인하십시오.


Georgios Emmanouil Stavropoulos
Georgios Emmanouil Stavropoulos 2018년 11월 19일
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
Anik Kumar Samanta
Anik Kumar Samanta 2018년 11월 30일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by