MATLAB: How to create a pie chart legend in the Matlab GUI

MATLABpie

I know how to plot a pie chart with a legend in Matlab. Now, I am creating a Matlab GUI that includes a pie chart. The pie chart is based on 8 values (numbers), which I derive from the variable 'a1'. Problem: I am not able to create legend for the pie chart.
I really appreciate any help you can provide.
pie(handles.axes5,data.a1);
legend(handles.axes5,'lables','Location','southoutside','Orientation','horizontal')
labels = {'A','B','C', 'D', 'F', 'G', 'H', 'I'};

Best Answer

alex1337 - you are using the following code to create your pie chart and legend
pie(handles.axes5,data.a1);
legend(handles.axes5,'lables','Location','southoutside','Orientation','horizontal')
labels = {'A','B','C', 'D', 'F', 'G', 'H', 'I'};
Note how you are passing a string as the second input parameter into legend. You need to pass a cell string array variable (which you need to declare before you try to use it). Try the following instead
pie(handles.axes5,data.a1);
labels = {'A','B','C', 'D', 'F', 'G', 'H', 'I'};
legend(handles.axes5,labels,'Location','southoutside','Orientation','horizontal')
Related Question