Change selected item in ListBox

52 views (last 30 days)
Mina Westphal
Mina Westphal on 10 May 2023
Commented: Mina Westphal on 11 May 2023
Hey,
I have to create a GUI to process EEG Data. The data has already been semi processed by me. When the app is opened, I load 3 different workspaces into a ListBox with the 'load Data' Button. When I choose "Paradigma 1" from the ListBox, I can then plot a single channel or more. So far, that works. Unfortunately I can't change the paradigm from the list box without closing the app and starting it again. I use the button "neues Paradigma" to at least clear the UIAxes. But I'd like to add code to the Button Function to be able to change the workspace I'm working with without having to reopen the app.
This is how I load the Data and assign it to the items in the List:
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: loadDataButton
function loadDataButtonPushed(app, event)
app.ws1 = load('App/app_p1.mat');
app.zeit = app.ws1.eeg_1;
app.t = app.ws1.t_1;
app.freq = app.ws1.EEG_1;
app.f = app.ws1.f_1;
app.F = app.ws1.F;
app.ws2 = load('App/app_p2.mat');
app.zeit = app.ws2.eeg_2;
app.t = app.ws2.t_2;
app.freq = app.ws2.EEG_2;
app.f = app.ws2.f_2;
app.F = app.ws2.F;
app.ws3 = load('App/app_p3.mat');
app.zeit = app.ws3.eeg_3;
app.t = app.ws3.t_3;
app.freq = app.ws3.EEG_3;
app.f = app.ws3.f_3;
app.F = app.ws3.F;
end
% Value changed function: ParadigmaAuswahlListBox
function ParadigmaAuswahlListBoxValueChanged(app, event)
value = app.ParadigmaAuswahlListBox.Value;
switch value
case 'Paradigma 1'
app.ws1;
case 'Paradigma 2'
app.ws2;
case 'Paradigma 3'
app.ws3;
end
end
  2 Comments
Mario Malic
Mario Malic on 10 May 2023
This should work, however, you could simplify your code a lot if you use ws instead of ws1, ws2, ws3.
function ParadigmaAuswahlListBoxValueChanged(app, event)
value = app.ParadigmaAuswahlListBox.Value;
switch value
case 'Paradigma 1'
app.ws1 = load('App/app_p1.mat');
% rest of the code
case 'Paradigma 2'
app.ws2 = load('App/app_p2.mat');
% rest of the code like in Paradigma 3
case 'Paradigma 3'
app.ws3 = load('App/app_p3.mat');
app.zeit = app.ws3.eeg_3;
app.t = app.ws3.t_3;
app.freq = app.ws3.EEG_3;
app.f = app.ws3.f_3;
app.F = app.ws3.F;
end
end
Mina Westphal
Mina Westphal on 11 May 2023
Thank you! That worked.

Sign in to comment.

Answers (1)

VBBV
VBBV on 11 May 2023
Edited: VBBV on 11 May 2023
Assign value as output argument to function ParadigmaAuswahlListBoxValue as shown below, and pass it as input argument to function loadDataButtonPushed , then use the switch-case code to load data and/or plot inside that function
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: loadDataButton
function loadDataButtonPushed(app, event,value)
switch value
case strcmp(value,'Paradigma 1')
app.ws1 = load('App/app_p1.mat');
app.zeit = app.ws1.eeg_1;
app.t = app.ws1.t_1;
app.freq = app.ws1.EEG_1;
app.f = app.ws1.f_1;
app.F = app.ws1.F;
case strcmp(value,'Paradigma 2')
app.ws2 = load('App/app_p2.mat');
app.zeit = app.ws2.eeg_2;
app.t = app.ws2.t_2;
app.freq = app.ws2.EEG_2;
app.f = app.ws2.f_2;
app.F = app.ws2.F;
case strcmp(value,'Paradigma 3')
app.ws3 = load('App/app_p3.mat');
app.zeit = app.ws3.eeg_3;
app.t = app.ws3.t_3;
app.freq = app.ws3.EEG_3;
app.f = app.ws3.f_3;
app.F = app.ws3.F;
end
end
% Value changed function: ParadigmaAuswahlListBox
function value = ParadigmaAuswahlListBoxValueChanged(app, event)
value = event.Value;
app.ParadigmaAuswahlListBox.Value = value;
end

Categories

Find more on Psychology in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!