How can I run a previously used function using a pushbutton?

2 visualizaciones (últimos 30 días)
Chris Gnam
Chris Gnam el 7 de Feb. de 2016
Respondida: Chris Gnam el 7 de Feb. de 2016
So I'm writing a code that will ask a user to input a matrix. It will then show them the matrix in a table, and ask them if it is correct. There will be a 'Yes' and a 'No' button. If they click the 'Yes' button, it will simply close the program. If they click the 'No' button, I would like it to go back and run the original function again, which asks them to input a matrix. I'm very confused, as I can't seem to figure out how you're supposed to do this, but it feels like this should be fairly easy... How can I make a pushbutton initiate a function which has already been used, without rewriting the entire function again? I can include my entire code if necesary, but it is rather lengthy, and all of it works properly except for the 'No' button. Basically my question comes down to this: Assuming that I write a rather lengthy function:
function matrix_input %Generate the actual window prompt
~ ~ ~ ~ ~ Lots of stuff going on in here including creating a window to input the matrix, and a 'submit' button
~ ~ ~ ~ ~
end
Which then opens up a second gui which displays the matrix and has the 'yes' and 'no' buttons:
function submitbtn_Callback
~ ~ ~ ~ Lots of stuff going on in here, including the creation of a 'matrixdisplay' window which has the two buttons on it
~ ~ ~ ~
end
How can I, later on, call back this function without needing to rewrite it all? I don't have any idea how to write this, but my best guess was something like this:
function nobtn_Callback(~, ~, matrixdisplay)
function matrix_input
end
end
In English, it'd be something like:
When nobtn is pressed, go to the function 'matrix_input' and do it again
I'm super lost, I feel like this should be relatively easy, so any help would be greatly appreciated!
  1 comentario
Geoff Hayes
Geoff Hayes el 7 de Feb. de 2016
Chris - are you using GUIDE to create your GUI(s)? Under what condition does matrix_input launch the second GUI? Finally, can't the nobtn_Callback just call the main program, matrix_input again (and close itself)?

Iniciar sesión para comentar.

Respuestas (1)

Chris Gnam
Chris Gnam el 7 de Feb. de 2016
I figured it out! All I need to do is put:
function nobtn_Callback(~, ~, matrixdisplay)
run matrix_input
end
And it worked perfectly!

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by