Error with Push Button Callback (including check boxes)
조회 수: 12 (최근 30일)
이전 댓글 표시
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319180/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319183/image.jpeg)
댓글 수: 0
채택된 답변
Devineni Aslesha
2020년 6월 24일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 National Instruments Frame Grabbers에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!