apply pie command to data in matlab

following simple declaration

grade=[11 18 26 9 5];

gives me following simple pie chart

but i want to make pie diagram from this structure

>> product(1).price=200;
>> product(2).name='hp';
>> product(2).price=1200;
>> product(2).name='apple';
>> product(3).name='dell';
>> product(3).price=600;
>> product(4).name='Toshiba';
>> product(4).price=700;

when i have applied,i have got

Undefined function 'le' for input arguments of type 'struct'.

Error in pie (line 35)
nonpositive = (x <= 0);

so how could i fix it?please help me,thanks in advance


pie() takes a matrix as input, not a struct array, so you need to extract the struct fields you want into a matrix. Luckily, this is very simple, since <structarray>.<field> returns a list of data that we can capture in a concatenation operator. This works for cell arrays too, so let's generate labels at the same time:

pie([product.price], {});

Need Your Help

IOS7 upgrade - Status bar not hiding on iPad

ipad ios6 ios7 upgrade ios7-statusbar

Hi I'm upgrading my Universal app from iOS6 to iOS7.