Get user input in app designer using toggle button group

6 次查看(过去 30 天)
Hello,
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
plot(app.UIAxes,alldata(:,z,i))
hold(app.UIAxes,'on')
end
for i = 13:50
plot(app.UIAxes2,alldata(:,z,i))
hold(app.UIAxes2,'on')
end
%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);
end
% Clear figures for next plot in app designer
hold(app.UIAxes,'off')
hold(app.UIAxes2,'off')
end

采纳的回答

Sam
Sam 2021-7-6
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);
end
function excludedata()
%add relevant matlab commands here
end
Once this is done, refer to this link on how to link code responce to button click.
  1 个评论
Anouk Heuvelmans
Anouk Heuvelmans 2021-7-7
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by