Change selected item in ListBox

조회 수: 10 (최근 30일)
Mina Westphal
Mina Westphal 2023년 5월 10일
댓글: Mina Westphal 2023년 5월 11일
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
Mario Malic
Mario Malic 2023년 5월 10일
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 2023년 5월 11일
Thank you! That worked.

댓글을 달려면 로그인하십시오.

답변 (1개)

VBBV
VBBV 2023년 5월 11일
편집: VBBV 2023년 5월 11일
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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by