How to create a GUI in matlab where the user can select a single testcase he wants to run?
11 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm trying to create a GUI for Model In loop Regression testing using the Matlab script. Here I have 100 testcases,
I want to select single testcase out of 100 and that selected testcase should run. I want the format to look like below
- Testcase 1
(i)TestCase1a
(ii)TestCase2a
2. TestCase 2
(i)TestCase1b
(ii)TestCse2b
etc
Currently, I'm using prompt command to enter the Testcase number I want to run. But I want to improvise this in GUI format which has all the testcases for the user selection.
Any inputs greatly appreciated!
Thank you!
4 个评论
Voss
2024-3-15
编辑:Voss
2024-3-17
You're welcome!
Here is a code structure you can use (you should take care that only one node is selected at a time, too):
function TreeSelectionChanged(app, event)
switch app.Tree.SelectedNodes
case app.Sensor1FaultNode % <- the name of Sensor1 Fault Node in your app
TC_RunNum = 10;
case app.Sensor2FaultNode % <- the name of Sensor2 Fault Node in your app
TC_RunNum = 11;
% etc.
end
% then run your script here
end
采纳的回答
Voss
2024-3-17
编辑:Voss
2024-3-17
I misunderstood the situation before; I thought you were running a script from an app, not the other way around.
If all you need is a single selection to set a variable in your script, you can run a simple GUI (not an app) from your script. Something like this would work. Here I'm using a popupmenu, but you could use a uitree.
function out = get_case_number()
f = figure( ...
'NumberTitle','off', ...
'IntegerHandle','off', ...
'HandleVisibility','off', ...
'Name','Select Case', ...
'Menubar','none', ...
'Toolbar','none', ...
'Units','pixels', ...
'Position',[300 400 200 140]);
p = uicontrol(f, ...
'Style','popupmenu', ...
'String',{'FNRFlt';'StrFlt';'Prkbrkswflt';'PBSolflt'}, ... % specify the case names
'UserData',[25;28;40;41], ... % and corresponding TC_RunNum value
'Value',1, ...
'Units','pixels', ...
'Position',[20 100 80 22]);
b = uicontrol(f, ...
'Style','pushbutton', ...
'String','Select', ...
'Units','pixels', ...
'Position',[30 20 65 22], ...
'Callback',@cb_button);
out = [];
uiwait(f);
function cb_button(~,~)
UD = get(p,'UserData');
out = UD(get(p,'Value'));
delete(f);
end
end
Then in your script, at the point where the user should make a selection, just say:
TC_RunNum = get_case_number();
and continue with the rest of the script, e.g.:
TC_size = size(TC_data);
TC_row = TC_size(1);
TC_RunNum = get_case_number();
TC_len = length(TC_data(:,TC_RunNum).Variables);
12 个评论
Voss
2024-3-20
See the attached modifed m-file.
You need the uiwait in order to be able to return the selected value. But also the button needs a callback, which was missing for uibutton. I put that in place.
Also, Value means different things for a uicontrol button vs a uibutton (as described in the links I posted earlier), so I fixed the button callback to work for a uibutton.
I also repositioned the objects to have a reasonable initial arrangement.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!