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

조회 수: 2 (최근 30일)
Chris Gnam
Chris Gnam 2016년 2월 7일
답변: Chris Gnam 2016년 2월 7일
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
Geoff Hayes
Geoff Hayes 2016년 2월 7일
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)?

댓글을 달려면 로그인하십시오.

답변 (1개)

Chris Gnam
Chris Gnam 2016년 2월 7일
I figured it out! All I need to do is put:
function nobtn_Callback(~, ~, matrixdisplay)
run matrix_input
end
And it worked perfectly!

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by