# Matlab GUI question

• MATLAB
calt3ch
So I am a bit unfamiliar with Callback functions etc. But here is what I want:

when someone clicks on a button, something happens. Well I want it so that when they click on another button and a certain condition isnt met, then the same function carried out by clicking a completely different button is carried out. I mean I guess I could just copy and paste the code so that it appears twice, but I feel like there's an easier way that involves just calling the functionnamehere_Callback function. Or am i crazy?

TylerH
This is a sign that you're not coding with good style. "Good" defined here as easy to follow and maintain.

Break the button handler function up into separate functions for each thing it does, and call that function from both button handler function.
Example:

Old:
Code:
button1()
{
// do stuff
}

button2()
{
// do same stuff
}

New:
Code:
button1()
{
do_stuff()
}

button2()
{
do_suff()
}

do_stuff()
{
// do stuff
}

This is called procedural programming, and it has it's own issues, but it's the common solution to your problem.

calt3ch
Yes of course. I was thinking of doing that before, but tbh I wasnt putting a whole lot of thought into the GUI code; it was kind of an unnecessary part of my project... but yes, good idea i will do that ultimately i guess :)