Get user input in app designer using toggle button group

22 views (last 30 days)
I've recently started using the app designer in Matlab and I'm trying to get user input in my app for the following:
I have a 3D-matrix with multiple datafiles that I want to judge for their quality and exclude if the quality is not good enough.
The analysis is started by clicking the 'Start analysis' button and subsequently, the first datafile is plotted. I plot the data in 2 graphs and based on these I want to either keep the data or exclude it and continue to the next datafile in the matrix. I thought of using a toggle button group for this, see below for how this would look.
I had previously written part of the script in a regular Matlab script of which I copied a part below to illustrate what my intention is. However, in the app I would like the user to be able to click the 'Keep data' box or 'Exclude data' box and consequently have the data either put in the data matrix or excluded_data matrix.
With my limited experience in app designer, I haven't been able to figure out how to implement a click on the toggle button in the start analysis. I have tried to watch some youtube video's/browsed the MathWorks community but it didn't get me very far yet.
Can anyone help with how I would be able to do this or give me some tips where to look for more information?
data = zeros(size(alldata));
data_filename = cell(size(allCCNames));
excluded_data = zeros(size(alldata));
excluded_filename = cell(size(allCCNames));
for z = 1:size(alldata,2)
for i = 1:12
for i = 13:50
%Matlab code outside app designer
choice = menu('Is the quality of the recording good enough?','Yes','No');
if choice == 1;
data(:,z,:) = alldata(:,z,:);
data_filename(1,z) = allCCNames(z);
elseif choice == 2;
excluded_data(:,z,:) = alldata(:,z,:);
excluded_filename(1,z) = allCCNames(z);
% Clear figures for next plot in app designer

Accepted Answer

Sam on 6 Jul 2021
Create two seperate MATLAB functions, one for keeping the data and other for excluding the data. Something similar to:
function keepdata()
data(:,z,:) = alldata(:,z,:);
data_filename(1,z) = allCCNames(z);
function excludedata()
%add relevant matlab commands here
Once this is done, refer to this link on how to link code responce to button click.
  1 Comment
Anouk Heuvelmans
Anouk Heuvelmans on 7 Jul 2021
Thank you for your answer Sam, I will put this in separate functions.
However then i still have a question about the callbacks. Do I create these functions under a callback of the togglebuttons or do I create a callback within the start analysis callback?

Sign in to comment.

More Answers (0)


Find more on Develop Apps Using App Designer 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!