Error when using legend or clicking on the plot

1 回表示 (過去 30 日間)
Ullas Rajvanshi
Ullas Rajvanshi 2016 年 10 月 26 日
編集済み: Walter Roberson 2016 年 11 月 5 日
Hi. I am a student whos studying MatLab basics. Am using a MacBook, and when I use the legend function while plotting it always gives me an error and am not able to get the legend. The error looks like this:
Attempt to execute SCRIPT allchild as a function:
/Users/ullasrajvanshi/Documents/MATLAB/allchild.m
Error in get_legendable_children (line 9)
legkids = allchild(ax);
Error in graph2dhelper (line 31)
[varargout{1:nargout}] = feval(varargin{:});
Error in legend>getLegendableChildren (line 620)
children = graph2dhelper('get_legendable_children', ha);
Error in legend>set_children_and_strings (line 632)
ch = getLegendableChildren(ha);
Error in legend>make_legend (line 334)
set_children_and_strings(ha,leg,children,strings);
Error in legend (line 282)
make_legend(ha,args(arg:end),version);
Also when I select any point on a figure, it also gives me an error. I have tried reinstalling MatLab but it doesnt work. Can anyone please help me
Thanks

採用された回答

Nick Counts
Nick Counts 2016 年 11 月 5 日
It looks like you have overloaded allchild.m
Enter "which allchild.m" in the command window. You should see something like this:
>> which allchild.m
/Applications/MATLAB_R2014b.app/toolbox/matlab/uitools/allchild.m
Based on your above, I predict you will get
/Users/ullasrajvanshi/Documents/MATLAB/allchild.m
Which means that you have defined a script and named it allchild.m
Now when Matlab trys to use its built-in function allchild() it is finding your script instead and things are breaking. You can rename your file or move it to a folder that isn't on the Matlab path and your issue should go away.
Good luck

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by