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

1 visualización (últimos 30 días)
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

Respuestas (1)

Kevin Phung
Kevin Phung el 9 de Abr. de 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

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by