Is an if statement needed to distinguish between two similar callbacks?

I have two push buttons in my GUIDE window. One is for opening files and reformatting them while the other does exactly the same thing but bins the data in half to allow for it to be plotted more quickly. Currently I just have both callbacks in the guide, but because they use exactly the same variable names and handles, I was thinking i may need to install an if statement to say;
If push button 1 is pushed, push button 2 is unused, and vice versa.
My query is, do i need a statement like this or could the code work without it?

3 Commenti

It depends what the usage scenarios are for the UI. If a user us expected to be clicking only one button and then close the UI after looking at some results then it doesn't matter much. If you want a robust tool where the user can press one button and then the other later on then you need to do some handling.
Exactly what needs doing depends on what the code is and how it is to be used though.
Using the same variable names in two different callbacks is not a problem at all if they are local to the callback's workspace rather than attached to handles.
The files would likely require too much memory if i were to open them using both buttons (if i were to use one and then later use the other). I will almost certainly only using one of the buttons and then looking at plots of the data. So you think I should be ok to carry on in the way I am?
You might as well use a radio button in a button group if the options are truly mutually exclusive.
Then if the user really does want to select the other option you would just throw away everything from the previous one, freeing the memory too.
How to handle this type of behaviour in a GUI is very much down to the usage though - if it is just for you to test some things out then clearly it can be as basic as you want. If you are packaging it up and releasing it as a piece of software for paying clients to use then obviously the standards need to be a lot higher.

Risposte (0)

Questa domanda è chiusa.

Prodotti

Richiesto:

il 4 Mag 2017

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by