Info

この質問は閉じられています。 編集または回答するには再度開いてください。

"Activate" lines with a GUI?

1 回表示 (過去 30 日間)
mec123
mec123 2016 年 7 月 27 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
Stefan Reich
Stefan Reich 2016 年 7 月 28 日
How about an if/else in the pushbotton_Callback function?
mec123
mec123 2016 年 7 月 28 日
Thank you! An if/else in the pushbutton reffering to the results of the if/else's of the checkboxes.

回答 (1 件)

Stephen23
Stephen23 2016 年 7 月 28 日
編集済み: Stephen23 2016 年 7 月 29 日
This is easy using nested functions (tested on MATLAB 2012b):
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
>>

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by