MATLAB Answers

0

why nothing is happening when i am calling other function in other button?

Asked by Dany Majed on 9 Apr 2019
Latest activity Answered by Kevin Phung on 9 Apr 2019
my question is that i have several pushbuttons and i have one pushbuttons that mainly controls them all so since i need my program to generate random number of presses from pushbuttons so i used this but nothing is happening why the callback for each button is not being performed since i do have other functions in other pushbuttons and i need once a press the last button to generate random presses of buttons containing several functions but nothing is working any help please since i am still a beginner
move = randi(6,1,10)
for i = 1:10
if move(1,1) == 1
pushbutton1_Callback
elseif move(1,1) == 2
pushbutton2_Callback
elseif move(1,1) == 3
pushbuttonD_Callback
elseif move(1,1) == 4
pushbuttonR_Callback
elseif move(1,1) == 5
pushbuttonF_Callback
elseif move(1,1) == 6
pushbuttonB_Callback
end
if move(1,2) == 1
pushbutton1_Callback
elseif move(1,2) == 2
pushbutton2_Callback
elseif move(1,2) == 3
pushbuttonD_Callback
elseif move(1,2) == 4
pushbuttonR_Callback
elseif move(1,2) == 5
pushbuttonF_Callback
elseif move(1,2) == 6
pushbuttonB_Callback
end
if move(1,3) == 1
pushbutton1_Callback
elseif move(1,3) == 2
pushbutton2_Callback
elseif move(1,3) == 3
pushbuttonD_Callback
elseif move(1,3) == 4
pushbuttonR_Callback
elseif move(1,3) == 5
pushbuttonF_Callback
elseif move(1,3) == 6
pushbuttonB_Callback
end
if move(1,4) == 1
pushbutton1_Callback
elseif move(1,4) == 2
pushbutton2_Callback
elseif move(1,4) == 3
pushbuttonD_Callback
elseif move(1,4) == 4
pushbuttonR_Callback
elseif move(1,4) == 5
pushbuttonF_Callback
elseif move(1,4) == 6
pushbuttonB_Callback
end
if move(1,5) == 1
pushbutton1_Callback
elseif move(1,5) == 2
pushbutton2_Callback
elseif move(1,5) == 3
pushbuttonD_Callback
elseif move(1,5) == 4
pushbuttonR_Callback
elseif move(1,5) == 5
pushbuttonF_Callback
elseif move(1,5) == 6
pushbuttonB_Callback
end
if move(1,6) == 1
pushbutton1_Callback
elseif move(1,6) == 2
pushbutton2_Callback
elseif move(1,6) == 3
pushbuttonD_Callback
elseif move(1,6) == 4
pushbuttonR_Callback
elseif move(1,6) == 5
pushbuttonF_Callback
elseif move(1,6) == 6
pushbuttonB_Callback
end
if move(1,7) == 1
pushbutton1_Callback
elseif move(1,7) == 2
pushbutton2_Callback
elseif move(1,7) == 3
pushbuttonD_Callback
elseif move(1,7) == 4
pushbuttonR_Callback
elseif move(1,7) == 5
pushbuttonF_Callback
elseif move(1,7) == 6
pushbuttonB_Callback
end
if move(1,8) == 1
pushbutton1_Callback
elseif move(1,8) == 2
pushbutton2_Callback
elseif move(1,8) == 3
pushbuttonD_Callback
elseif move(1,8) == 4
pushbuttonR_Callback
elseif move(1,8) == 5
pushbuttonF_Callback
elseif move(1,8) == 6
pushbuttonB_Callback
end
if move(1,9) == 1
pushbutton1_Callback
elseif move(1,9) == 2
pushbutton2_Callback
elseif move(1,9) == 3
pushbuttonD_Callback
elseif move(1,9) == 4
pushbuttonR_Callback
elseif move(1,9) == 5
pushbuttonF_Callback
elseif move(1,9) == 6
pushbuttonB_Callback
end
if move(1,10) == 1
pushbutton1_Callback
elseif move(1,10) == 2
pushbutton2_Callback
elseif move(1,10) == 3
pushbuttonD_Callback
elseif move(1,10) == 4
pushbuttonR_Callback
elseif move(1,10) == 5
pushbuttonF_Callback
elseif move(1,10) == 6
pushbuttonB_Callback
end
end

  0 Comments

Sign in to comment.

Products


Release

R2018a

1 Answer

Answer by Kevin Phung on 9 Apr 2019

what is supposed to be happening? My guess is that something IS happening, except your callback functions are not returning anything because variables you are creating within those functions are only created within the scope of that particular function. Also, I recommend using the Switch/case method as opposed to if/else.
example:
if move(1,1) == 1
pushbutton1_Callback
elseif move(1,1) == 2
pushbutton2_Callback
elseif move(1,1) == 3
pushbuttonD_Callback
elseif move(1,1) == 4
pushbuttonR_Callback
elseif move(1,1) == 5
pushbuttonF_Callback
elseif move(1,1) == 6
pushbuttonB_Callback
end
%Versus
switch move(1,1)
case 1
pushbutton1_Callback
case 2
pushbutton2_Callback
case 3
pushbuttonD_Callback
case 4
pushbuttonR_Callback
case 5
pushbuttonF_Callback
case 6
pushbuttonB_Callback
end

  0 Comments

Sign in to comment.