programming philosophy for GUIs
Show older comments
Hi.
This is a fairly broad question, but I would like to know how people handle GUIs in matlab, and how it interfaces with a more "traditional" programming style. More specifically, I am using matlab to display visual stimuli and I have accumulated experience in how to write my code to have good timing and be reliable, bug-free. Now, I need to design a GUI so that people with no knowledge of matlab can use my scripts, change parameter values etc. I have managed to do roughly the same same using timer events and a GUI as I would usually do with a traditional sequential script. But I know timings are not reliable this way, plus the code is very messy and prone to bugs.
So how do people usually solve these kind of issues? Can I run a script in parallel of the GUI? Should I use the GUI to set up parameters, close it to run whatever important peice of code I want to run, and reopen it again when timing becomes less critical? I'm not clear on what's the best way to proceed. Any advice or general guidance would be appreciated.
Thanks.
4 Comments
It sounds like you have a series of scripts (or functions?) that depend on a set of parameters that you set prior to running the scripts. If that's the case, a GUI can certainly handle that and there should be no reason the code becomes messy or buggy just because it's being run from a GUI. As for the timing issues, what level of temporal precision are you looking for? Milliseconds? Hundreds of ms?
"Can I run a script in parallel of the GUI"
If you already have the code that executes your program and the GUI is set up so that the user can choose initial values, then all the GUI really needs to do is gather the user-defined values and send those parameters to your functions. If the GUI is more interactive than that and you think this could cause problems, it would be helpful to have more details on that.
"Should I use the GUI to set up parameters, close it to run whatever important peice of code I want to run, and reopen it again when timing becomes less critical?"
Again, if you already have functional code and you just want the user to choose initial parameters, it shouldn't be too labor intensive for the GUI to merely collect the user input and send it to your function. No need to shut it down and start it back up. You could control the visible parameter so the GUI disapears when your function is running. This advice all depends on what you're doing.
Walter Roberson
on 11 Dec 2018
I am using matlab to display visual stimuli
I have managed to do roughly the same same using timer events
Sounds to me as if you should be investigating Psychtoolbox http://psychtoolbox.org/
Baptiste Caziot
on 11 Dec 2018
Walter Roberson
on 11 Dec 2018
My understanding is that you can do that if you use different displays.
I have not looked at PTB enough to know whether it is possible to temporarily turn off it handling the screen while you run a GUI, then hide the GUI and give control of the screen to PTB.
I suspect it is not possible to have part of a screen controled by PTB and a different part not controlled.
Answers (0)
Categories
Find more on Timing and presenting 2D and 3D stimuli in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!