Can't switch between the contents of two different ListBoxes

5 visualizaciones (últimos 30 días)
I need to create a GUI with Matlab App Designer. I'm processing EEG-Data. After loading the Data into the first ListBox called SignalListBox I can plot or filter the data. After filtering, I save the filtered data as a new Workspace and load it into a second ListBox called ListBox. Following that, I'd like to be able to change between the ListBoxes. So far, I can only use the data of SignalListBox and not switch, once I have created the second ListBox with filtered data.
GUI after creating the second Box
This is the code for the both boxes,
properties (Access = private)
% other variables I've used
useFilteredData = false;
end
function SignalListBoxValueChanged(app, event)
value = app.SignalListBox.Value;
if app.useFilteredData
value = app.ListBox.Value;
else
value = app.SignalListBox.Value;
app.ws = 'Paradigma 2';
end
end
% Value changed function: ListBox
function ListBoxValueChanged(app, event)
value = app.ListBox.Value;
if app.useFilteredData
value = app.ListBox.Value;
app.ws_filt = 'Paradigma 2 gefiltert';
else
value = app.SignalListBox.Value;
end
end
% Button pushed function: plotButton
function plotButtonPushed(app, event)
if app.useFilteredData
app.t = app.t_f;
app.zeit = app.zeit_filt;
app.f = app.f_f;
app.freq = app.freq_filt;
else
app.t = app.t;
app.zeit = app.zeit;
app.f = app.f;
app.freq = app.freq;
end
if app.FPzCheckBox.Value
plot(app.UIAxes, app.t, app.zeit(:,1));
plot(app.UIAxes2, app.f, abs(app.freq(:,1)));
hold(app.UIAxes, 'on');
hold(app.UIAxes2, 'on');
end
% plot directions for other checkboxes
end
in my filter function, I set the useFilteredData variable to true
function FilterButtonPushed(app, event)
% filtering the data...
save('/Users/mina/Desktop/App/app_p2_filt.mat','zeit_filt','freq_filt','t_f','f_f')
app.ws_filt = load('App/app_p2_filt.mat');
app.ListBox.Items = {'Paradigma 2 gefiltert'};
app.ListBox.ItemsData = app.ws_filt;
app.ListBox.Enable = true;
app.ListBox.Visible = 'on';
app.useFilteredData = true;
end
The error I get is 'Index in position 2 exceeds array bounds.' referring to the first plot() line. I've checked and I can plot both filtered and unfiltered data from the workspace using: plot(t_f,zeit_filt(:,1)); So I suppose theres something wrong when switching the bool variable, but I can't figure out what.
  4 comentarios
Jon
Jon el 11 de Mayo de 2023
OK, now I can begin to look at your code, but because, I'm not familiar with the specifics of your application, and it is not in English, I'm not sure how to use your user interface. Can you please list the steps to take to reproduce your problem.
Mina Westphal
Mina Westphal el 12 de Mayo de 2023
Of course, sorry. First you click "laden" to load the workspace. Then you select Paradigma 2. Where it says "Wende einen Bandpass-Filter an" you have the options to put in the lower and upper Frequency you want the signal Paradigma 2 to be filtered by. Then you click "filter" and the second ListBox with "Paradigma 2 gefiltert" should appear. Then you select that new "Paradigma 2 gefiltert" and choose one or all of the channels under "Kanäle" you want to see plotted. And then when you click on the "plot" button you should get the same error that I did.

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 11 de Mayo de 2023
I think the issue is that you have loaded your filtered data to the structure app.ws_filt, yet in your plotting code, you are treating the data as if it were loaded to app.
I think you need to keep your load comand the same, which means you need to update the if statement at the top of your Plot callback to load the filtered data from app.ws_filt
if app.useFilteredData
app.t = app.ws_filt.t_f;
app.zeit = app.ws_filt.zeit_filt;
app.f = app.ws_filt.f_f;
app.freq = app.ws_filt.freq_filt;
  4 comentarios
Jon
Jon el 12 de Mayo de 2023
In addition to @Cris LaPierre correction, you must also modify the code below, commenting out your assignment of the string 'Paradigma 2 gefiltert' to app.ws_filt. If you don't do this you wipe out all of the data that you loaded in app.ws_filt
Also this callback then actually does nothing. So selecting the second list box, which calls this function doesn't do anything, but apparently it is not needed, as the code will run.
Probably @Cris LaPierre never clicked on that box so this function wasn't called. That's why the code ran for him
% Value changed function: ListBox
function ListBoxValueChanged(app, event)
value = app.ListBox.Value;
if app.useFilteredData
value = app.ListBox.Value;
% % % app.ws_filt = 'Paradigma 2 gefiltert'; %****
else
value = app.SignalListBox.Value;
end
end
Mina Westphal
Mina Westphal el 12 de Mayo de 2023
Thank you to both of you. Now it's working as intended.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by