Info
This question is closed. Reopen it to edit or answer.
"Activate" lines with a GUI?
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Stephen23
on 28 Jul 2016
Edited: Stephen23
on 29 Jul 2016
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 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!