Info
此问题已关闭。 请重新打开它进行编辑或回答。
"Activate" lines with a GUI?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
i am very new to Matlab so please no blame for "bad" questions.
What I have is a script to do some calculations and display the results afterwards in separate windows. Since i never need all results at the same time, i created a GUI with checkboxes and a "run" button. This way i want to reduce the high calculation time.
My first target is the following:
With the checkboxes i want to determine, which commands / parts of the script are supposed to be run. Triggering the boxes must not activate anything before the "run" button is clicked. Hitting the "run"-Button activates the script like usual, just with less commands.
So instead of
1
2
3
4
5
i want to get something like
1
2
3
checkbox -> 4
checkbox -> 5
checkbox -> 6
To start with i want to be able to switch on/off "figure"-commands.
I hope it is roughly clear what i'm trying to tell.
Thanks
2 个评论
回答(1 个)
Stephen23
2016-7-28
编辑:Stephen23
2016-7-29
function temp0
%
F = figure();
P = uipanel(...
'Parent',F,...
'Units','normalized',...
'Position',[0.1,0.1,0.7,0.6]);
%
N = 5;
V = 0:N;
H = V;
gap = 0.1;
hgt = (1-(N+1)*gap)/N;
for k = 1:N
H(k) = uicontrol(...
'Parent',P,...
'String',sprintf('Option %d',k),...
'Style','checkbox',...
'Units','normalized',...
'Position',[0.1,gap+(gap+hgt)*(N-k),0.8,hgt]);
end
%
uicontrol(...
'Parent',F,...
'String','Run',...
'Style','pushbutton',...
'Units','normalized',...
'Position',[0.1,0.8,0.7,0.1],...
'Callback',@MyFun);
%
function MyFun(~,~)
for n = 1:N
if get(H(n),'Value')
fprintf('Option %d has been selected\n',n)
... your code here
end
end
end
%
end
And produces this figure with several checkboxes:
And when "run" is clicked it prints this in the command window
>> temp0()
Option 1 has been selected
Option 3 has been selected
Option 4 has been selected
>>
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!