Error when using legend or clicking on the plot

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Nick Counts
Nick Counts il 5 Nov 2016
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

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by