Clear Filters
Clear Filters

drop down list and function

9 views (last 30 days)
Indri Ristika Utami
Indri Ristika Utami on 30 Jun 2023
Edited: Ram Sreekar on 12 Jul 2023
so i made a simple guide with one of the features is the drop down list, but i find the diffilcuties by connecting the input menu from the drop down list to other function. this is my codes, so the purpose is user can choose one of this filters.
%---------------------------- F I L T E R ---------------------------------
%----------------------------- D E L T A ----------------------------------
Fs = 100;
order = 12;
f_low = 1;
f_high = 4;
[Delta] = Bandpass_Butter(f_low,f_high,Fs,order)
data_Delta = filter(Delta, Filtered_Data);
%----------------------------- T H E T A ----------------------------------
order = 12;
f_low = 4;
f_high = 8;
[Theta] = Bandpass_Butter(f_low,f_high,Fs,order)
data_Theta = filter(Theta, Filtered_Data);
%----------------------------- A L P H A ----------------------------------
order = 12;
f_low = 8;
f_high = 14;
[Alpha] = Bandpass_Butter(f_low,f_high,Fs,order)
data_Alpha = filter(Alpha, Filtered_Data);
%------------------------------ B E T A -----------------------------------
order = 12;
f_low = 14;
f_high = 30;
[Beta] = Bandpass_Butter(f_low,f_high,Fs,order)
data_Beta = filter(Beta, Filtered_Data);
%----------------------------- G A M M A ----------------------------------
order = 12;
f_low = 30;
f_high = 40;
[Gamma] = Bandpass_Butter(f_low,f_high,Fs,order)
data_Gamma = filter(Gamma, Filtered_Data);
  1 Comment
Image Analyst
Image Analyst on 30 Jun 2023
If you have any more questions, then attach your .m and .fig files with the paperclip icon after you read this:

Sign in to comment.

Answers (1)

Ram Sreekar
Ram Sreekar on 12 Jul 2023
Edited: Ram Sreekar on 12 Jul 2023
Hi Indri Ristika Utami ,
I understand that you are trying to execute the function ‘Bandpass_Butter’ and ‘filter’ with different values for “f_low”, “f_high” based on the selection from dropdown.
This can be done by using the ‘switch’ statement and assigning different values to “f_low” and “f_high” based on the selection in the dropdown. You can refer to the sample code given below.
% Create a figure to hold the GUI elements
figure('Name', 'Filter Selection');
% Create a drop-down menu
filterMenu = uicontrol('Style', 'popupmenu', 'String', {'Delta', 'Theta', 'Alpha', 'Beta', 'Gamma'},...
'Position', [200 200 100 100], 'Callback', @filterSelectionCallback);
% Define the callback function for the drop-down menu
function filterSelectionCallback(source, ~)
% Get the selected filter from the drop-down menu
selectedFilter = source.Value;
% Define the filter parameters based on the selected option
switch selectedFilter
case 1 % Delta
f_low = 1;
f_high = 4;
case 2 % Theta
f_low = 4;
f_high = 8;
case 3 % Alpha
f_low = 8;
f_high = 14;
case 4 % Beta
f_low = 14;
f_high = 30;
case 5 % Gamma
f_low = 30;
f_high = 40;
end
% Apply the selected filter
Fs = 100;
order = 12;
[filter] = Bandpass_Butter(f_low, f_high, Fs, order);
filteredData = filter(filter, Filtered_Data);
% Perform any further processing or display as needed
end
Hope this helps you resolve your query.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!