Matlab GUI question

  • MATLAB
  • Thread starter calt3ch
  • Start date
  • #1
calt3ch
4
0
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?
 

Answers and Replies

  • #2
TylerH
724
0
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.
 
  • #3
calt3ch
4
0
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 :)
 

Suggested for: Matlab GUI question

  • Last Post
Replies
1
Views
4K
  • Last Post
Replies
0
Views
6K
  • Last Post
Replies
1
Views
8K
  • Last Post
Replies
0
Views
2K
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
0
Views
2K
  • Last Post
Replies
6
Views
22K
  • Last Post
Replies
0
Views
2K
  • Last Post
Replies
0
Views
5K
  • Last Post
Replies
0
Views
8K
Top