周计划 补完工程 第十三周 matlab练习

来源:互联网 发布:pymongo 删除数据 编辑:程序博客网 时间:2024/05/22 15:28

一周一个小项目,本周是第十三周,工作目标为matlab练习

本周练习饼图绘制,目标是画出一个饼图

可以展示三个产品市场份额的饼图

任何问题都可以提哦

代码如下

function week13 %%饼图
h0=figure('toolbar','none','position',[200 150 450 250],'name','week 13');
t=[54 21 35;
68 54 35;
45 25 12;
48 68 45;
68 54 69];
x=sum(t);
h=pie(x);
textobjs=findobj(h,'type','text');
str1=get(textobjs,{'string'});
val1=get(textobjs,{'extent'});
oldext=cat(1,val1{:});
names={'product1:';'product2:';'product3:'};
str2=strcat(names,str1);
set(textobjs,{'string'},str2)
val2=get(textobjs,{'extent'});
newext=cat(1,val2{:});
offset=sign(oldext(:,1)).*(newext(:,3)-oldext(:,3))/2;
pos=get(textobjs,{'position'});
textpos=cat(1,pos{:});
textpos(:,1)=textpos(:,1)+offset;
set(textobjs,{'position'},num2cell(textpos,[3,2]))




原创粉丝点击