matlab中循环如何用点击按钮来结束
functiong=licu()A=[0.5;0.5];n=500;figure('color','w');axis([-3,3,0,10]);stop=uicontro...
function g=licu()
A=[0.5;0.5];
n=500;
figure('color','w');
axis([-3,3,0,10]);
stop=uicontrol('style','toggle','string','停止','background','white');
plot(A(1),A(2),'.g');
while (n)%如何将图标按钮运用在循环条件中,控制循环,这是我自己规定的迭代500次
title('蕨类植物的叶片');
x=unifrnd(0,1);
if x>0.15
B=[0.85,0.04;-0.04,0.85]*A;
B(2)=B(2)+1.6;
hold on;
h=plot(A(1),A(2),B(1),B(2));
set(h,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=B;
elseif x>0.08
C=[0.2,-0.26;0.23,0.22]*A;
C(2)=C(2)+1.6;
hold on;
h1=plot(A(1),A(2),C(1),C(2));
set(h1,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=C;
elseif x>0.01
D=[-0.15,0.28;0.26,0.24]*A;
D(2)=D(2)+0.44;
hold on;
h2=plot(A(1),A(2),D(1),D(2));
set(h2,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=D;
else
E=[0,0;0,0.16]*A;
hold on;
h3=plot(A(1),A(2),E(1),E(2));
set(h3,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
end
n=n-1;
end
axis off;
end
这我做的想要通过点击图片上的停止按钮结束循环如何改进 展开
A=[0.5;0.5];
n=500;
figure('color','w');
axis([-3,3,0,10]);
stop=uicontrol('style','toggle','string','停止','background','white');
plot(A(1),A(2),'.g');
while (n)%如何将图标按钮运用在循环条件中,控制循环,这是我自己规定的迭代500次
title('蕨类植物的叶片');
x=unifrnd(0,1);
if x>0.15
B=[0.85,0.04;-0.04,0.85]*A;
B(2)=B(2)+1.6;
hold on;
h=plot(A(1),A(2),B(1),B(2));
set(h,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=B;
elseif x>0.08
C=[0.2,-0.26;0.23,0.22]*A;
C(2)=C(2)+1.6;
hold on;
h1=plot(A(1),A(2),C(1),C(2));
set(h1,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=C;
elseif x>0.01
D=[-0.15,0.28;0.26,0.24]*A;
D(2)=D(2)+0.44;
hold on;
h2=plot(A(1),A(2),D(1),D(2));
set(h2,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=D;
else
E=[0,0;0,0.16]*A;
hold on;
h3=plot(A(1),A(2),E(1),E(2));
set(h3,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
end
n=n-1;
end
axis off;
end
这我做的想要通过点击图片上的停止按钮结束循环如何改进 展开
3个回答
展开全部
试试修改后的代码
function g=licu()
global n
A=[0.5;0.5];
n=1;
figure('color','w');
hold on;
axis off;
axis([-3,3,0,10]);
plot(A(1),A(2),'.g');
title('蕨类植物的叶片');
stop=uicontrol('style','toggle','string','停止','background','white','Callback','forcestop');
static=uicontrol('style','text','Position',[20 50 100 15],'String','count:0')
count=0;
while (n)%如何将图标按钮运用在循环条件中,控制循环,这是我自己规定的迭代500次
x=unifrnd(0,1);
if x>0.15
B=[0.85,0.04;-0.04,0.85]*A;
B(2)=B(2)+1.6;
h=plot(A(1),A(2),B(1),B(2));
set(h,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=B;
elseif x>0.08
C=[0.2,-0.26;0.23,0.22]*A;
C(2)=C(2)+1.6;
h1=plot(A(1),A(2),C(1),C(2));
set(h1,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=C;
elseif x>0.01
D=[-0.15,0.28;0.26,0.24]*A;
D(2)=D(2)+0.44;
h2=plot(A(1),A(2),D(1),D(2));
set(h2,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=D;
else
E=[0,0;0,0.16]*A;
h3=plot(A(1),A(2),E(1),E(2));
set(h3,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
end
count=count+1;
set(static,'String',['count:',num2str(count)])
pause(.01)
end
end
function n=forcestop()
global n
n=0;
end
function g=licu()
global n
A=[0.5;0.5];
n=1;
figure('color','w');
hold on;
axis off;
axis([-3,3,0,10]);
plot(A(1),A(2),'.g');
title('蕨类植物的叶片');
stop=uicontrol('style','toggle','string','停止','background','white','Callback','forcestop');
static=uicontrol('style','text','Position',[20 50 100 15],'String','count:0')
count=0;
while (n)%如何将图标按钮运用在循环条件中,控制循环,这是我自己规定的迭代500次
x=unifrnd(0,1);
if x>0.15
B=[0.85,0.04;-0.04,0.85]*A;
B(2)=B(2)+1.6;
h=plot(A(1),A(2),B(1),B(2));
set(h,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=B;
elseif x>0.08
C=[0.2,-0.26;0.23,0.22]*A;
C(2)=C(2)+1.6;
h1=plot(A(1),A(2),C(1),C(2));
set(h1,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=C;
elseif x>0.01
D=[-0.15,0.28;0.26,0.24]*A;
D(2)=D(2)+0.44;
h2=plot(A(1),A(2),D(1),D(2));
set(h2,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
A=D;
else
E=[0,0;0,0.16]*A;
h3=plot(A(1),A(2),E(1),E(2));
set(h3,{'LineWidth'},{8;8},{'Color'},{'g';'g'},{'LineStyle'},{'*';'*'})
end
count=count+1;
set(static,'String',['count:',num2str(count)])
pause(.01)
end
end
function n=forcestop()
global n
n=0;
end
展开全部
可以设计一个全局的变量flag,初始化为1,点图片上的停止按钮以后赋值为0,上面的while就检测flag的取值。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把
while (n)
改成
while (n&&get(stop,'value'))
应该就可以了。
while (n)
改成
while (n&&get(stop,'value'))
应该就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询