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
  1 件のコメント
Mina Westphal
Mina Westphal 2023 年 5 月 11 日
Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop 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