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
  1. 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
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
jenny
jenny 2024-3-16
I have added the switch cases in the mlapp file
I tried to call this mlapp file from .m script by running
run("app1.mlapp");
Looks like it is not running that command and going through the other lines of the .m script. Below is the .m script(just initial couple of lines)
clc;
run("app1.mlapp");
TC_size = size(TC_data);
TC_row = TC_size(1);
TC_len = length(TC_data(:,TC_RunNum).Variables);
After running the above lines, it throughs the below error:
Unrecognized function or variable 'TC_RunNum'.
Error in RunSelectTC (line 40)
TC_len = length(TC_data(:,TC_RunNum).Variables);
I have mentioned the TC_RunNum in the .mlapp file like below
methods (Access = private)
% Selection changed function: Tree
function TreeSelectionChanged(app, event)
switch app.Tree.SelectedNodes
case app.FNRFltNode
TC_RunNum = 25;
case app.StrFltNode %
TC_RunNum = 28;
case app.PrkbrkswfltNode
TC_RunNum = 40;
case app.PBSolfltNode
TC_RunNum = 41;
end
Quesions:
  1. How to call the mlapp file in the .m script? so that user can select the testcase.
  2. The mlapp file which I'm creating is only for the testcase selection. Once the user selects the testcase, it should come back to the .m script. Should I add any logic over here in the mlapp script to go back to .m script? Or something to do add in the m script?
Thank you!!

请先登录,再进行评论。

采纳的回答

Voss
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
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.
jenny
jenny 2024-3-21
Thank you so much!!
idx = find(strcmp(get(p,'Items'),get(p,'Value')),1);
Sorry, I did not understand 'Value' in the get command

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by