Error with Push Button Callback (including check boxes)

3 views (last 30 days)
So for the following code shown below, I have made a figure, which includes 13 checkboxes - each with different years from 2018 to 2006 (Section A). This produces the figure as I have wanted (Image 1). With btn being included at the end of Section A, I am trying to make it such that when the user clicks on the button (after selecting the years that they want), MATLAB would check every checkbox to see if it is true or not. If it is true (i.e. checked), then it would go to Section B, where it gets the data from a EXCEL table on my MATLAB Folder.
Every time I run the test, I always get an error for btn (Image 2), with errors also with my for loop in Section B. I know that something is wrong with btn, but I do not understand how (or why). In addition, is there any way to make all of this simpler and less complicated?
In summary:
1) Why is the line including btn not working?
2) What silly mistake have I made which leads to the for loop to also produce an error?
Thank you for any feedback and any suggestions on how I could improve this.
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Section A %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fig=uifigure('Name','Additional Year Selection','Position',[100 100 350 276]);
bg=uibuttongroup('Parent',fig,'Position',[10 70 330 180]);
cbx1 = uicheckbox(bg,'Text','2018','Position',[20 150 91 15],'FontSize',19);
cbx2 = uicheckbox(bg,'Text','2017','Position',[20 120 91 15],'FontSize',19);
cbx3 = uicheckbox(bg,'Text','2016','Position',[20 90 91 15],'FontSize',19);
cbx4 = uicheckbox(bg,'Text','2015','Position',[20 60 91 15],'FontSize',19);
cbx5 = uicheckbox(bg,'Text','2014','Position',[20 30 91 15],'FontSize',19);
cbx6 = uicheckbox(bg,'Text','2013','Position',[130 150 91 15],'FontSize',19);
cbx7 = uicheckbox(bg,'Text','2012','Position',[130 120 91 15],'FontSize',19);
cbx8 = uicheckbox(bg,'Text','2011','Position',[130 90 91 15],'FontSize',19);
cbx9 = uicheckbox(bg,'Text','2010','Position',[130 60 91 15],'FontSize',19);
cbx10 = uicheckbox(bg,'Text','2009','Position',[130 30 91 15],'FontSize',19);
cbx11 = uicheckbox(bg,'Text','2008','Position',[240 150 91 15],'FontSize',19);
cbx12 = uicheckbox(bg,'Text','2007','Position',[240 120 91 15],'FontSize',19);
cbx13 = uicheckbox(bg,'Text','2006','Position',[240 90 91 15],'FontSize',19);
btn = uibutton(fig,'Text','Continue','Position',[120 25 100 22],'ButtonPushedFcn', @(btn,event) getdatafromTRA0104(btn,cbx));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Section B %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function getdatafromTRA0104(cbx)
for i=1:13
val=cbx(i).Value;
if val==true
[Road_Class,CarsTaxis,LCVs,HGVs,Motorcycles,BusesCoaches,TotalOtherVehicles,All_Vehicles] = TableSelectionC2(cbx(i));
end
end
end
(Image 1)
(Image 2)

Accepted Answer

Devineni Aslesha
Devineni Aslesha on 24 Jun 2020
Hi Chirag,
In the given code, the reason for the error "Too many input arguments" is that the getdatafromTRA0104 function is defined with one input argument cbx. However, in line 17, the function is called with two input arguments btn and cbx. So, you can call the function as getdatafromTRA0104(cbx) in line 17. Also, there is no variable defined as cbx in the given code. Modify cbx1 to cbx(1) to use cbx in the for loop. Similarly, modify cbx2 to cbx(2) and so on.
  1 Comment
Chirag Chavda
Chirag Chavda on 26 Jun 2020
Edited: Chirag Chavda on 26 Jun 2020
Thank you very much for your help! Apologies for the late reply

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!