遵循简单声明
grade=[11 18 26 9 5];
pie(grade)
给了我简单的饼图
但我想从这个结构中制作饼图
product(1).name='hp';
>> 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;
当我申请时,我有
pie(product)
Undefined function 'le' for input arguments of type 'struct'.
Error in pie (line 35)
nonpositive = (x <= 0);
所以我怎么能解决它?请帮助我,提前谢谢
答案 0 :(得分:2)
pie()
将矩阵作为输入,而不是结构数组,因此您需要将所需的结构域提取到矩阵中。幸运的是,这非常简单,因为我们可以在连接运算符中捕获<structarray>.<field>
returns a list of data。这也适用于单元格数组,所以让我们同时生成标签:
pie([product.price], {product.name});