关于matlab调速风扇0
代码如下
clear
speed = 100;
t = 0;
Y_a = 4;Y_b = 4;Y_c = 4;
y0 = figure;
axis equal;axis off
axis([-6 6 -10 6])
title('可调速电风扇','fontsize',15);
grid off;
[x1,y1,z1]=sphere(30); %产生球体坐标
x=5*x1;y=5*y1;z=5*z1;
shading interp;
hold on;
mesh(x,y,z),colormap(hot); %画风扇框架
hold on;
hidden off;
hold on;
fill([-3,-1,1,3],[-8.5,-5,-5,-8.5],[0.5,0.5,0.5]); %画一个多边形
text(-0.6,-6,'xxxx ','color','k'); %多边形里的文字
text(-1.2,-7,'xxxxxxx ','color','k'); %多边形里的文字
hold on
ax = Y_a * cos(2 * pi * t);ay = Y_a * sin(2 * pi * t); %计算初始三个叶片的横坐标和纵坐标
bx = Y_b * cos(2 * pi * t - 2 * pi/3);by = Y_b * sin(2 * pi * t - 2 * pi/3);
cx = Y_c * cos(2 * pi * t + 2 * pi/3);cy = Y_c * sin(2 * pi * t + 2 * pi/3);
y_line_a = line([0 ax],[0 ay],'EraseMode','xor','Color','r','linestyle','-','linewidth',20); %画出三个叶片
y_line_b = line([0 bx],[0 by],'EraseMode','xor','Color','b','linestyle','-','linewidth',20);
y_line_c = line([0 cx],[0 cy],'EraseMode','xor','Color','g','linestyle','-','linewidth',20);
k=1;
%b0为开始按钮
…… ……
while 1 %让风扇转起来的循环
if k==0
drawnow;
elseif k==1
t = t + 1/speed;
ax = Y_a * cos(2 * pi * t);ay = Y_a * sin(2 * pi * t);
bx = Y_b * cos(2 * pi * t - 2 * pi/3);by = Y_b * sin(2 * pi * t - 2 * pi/3);
cx = Y_c * cos(2 * pi * t + 2 * pi/3);cy = Y_c * sin(2 * pi * t + 2 * pi/3);
drawnow;
set(y_line_a,'XData',[0 ax],'YData',[0 ay]);
set(y_line_b,'XData',[0 bx],'YData',[0 by]);
set(y_line_c,'XData',[0 cx],'YData',[0 cy]);
end
end
每次停止运行就会出现“??? Error using ==> set
Invalid handle.
Error in ==> D:\matlab\bin\win32\fs.m
On line 94 ==> set(y_line_a,'XData',[0 ax],'YData',[0 ay]);”请问该怎么解决?还有风扇底座可以怎么再美化一下吗?