is it possible to create a matlab script directly from gui pushbutton events (kind of like command line history)?

3 views (last 30 days)
I created a GUI in appdesigner to do various manipulations of the raw (time domain) MRI data. After various combinations of buttons clicks, I would like to save that combination as a *.m script, so that I can come back a year from now to the dataset and reproduce the data processing protocol. Not as a batch mode within the interface, but have the actual *.m script explicitely specifying each step.
E.g. In the GUI interface: Action 1: subtract dc offset, Action 2: Multiply the data by a gaussian filter, Action 3: FFT
At the end of 3 button pushes, I want to get a script *.m:
.... there can be 10 or 15 pushbuttons events that I essentially would like to save to a script and store this with the original dataset.
Thank you!
  1 Comment
Jiri Hajek
Jiri Hajek on 25 Jan 2023
Edited: Jiri Hajek on 25 Jan 2023
Hi, in principle, I;m not aware of any ready-to use or diary-like way to recort the sequence that would not require additioal coding. However, if you are not using the diary command in your app for other purposes, I'd still consider it a good way to output the desired lines of code to a text file. M-file is a simple text file after all.
I've been using diaries in apps to create log files for years, in this case it's essentially the same concept.

Sign in to comment.

Answers (1)

Rik on 25 Jan 2023
Edited: Rik on 25 Jan 2023
If you don't use numbered variables, you can include an fprintf statement that will write a line to a text file. There is no automated way to extract the text of the current function, so you will need to manually create that.
I doubt diary will work in the context of callbacks, but if you like that idea you can give it a try. If it does work, the downside will be that you van only have 1 at a time, while you can have about 200 log files open at a time if you use fopen.


Find more on Package and Share Apps 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!