How to disable GUI M-file with the same name as FIL file
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Valeriy
am 29 Mai 2018
Kommentiert: Valeriy
am 9 Jun. 2018
Hi everybody. I have created GUI, using guide and saved it in FIG figure file. While saving this figure, M-file with the same, as figure name, is created. I don't like to use it, all necessary code I have wrote in another M-file with another than figure name. How to disable execution of the M-file with the same as figure name? I suppose that such interaction of two M-files blocked correct execution.
Where in FIG file is stored name of corresponding M-file?
Thank you
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 8 Jun. 2018
When you save a function file, MATLAB knows the main function in that file by the name of the file, not the name in the function declaration line, as stated on this documentation page.
In your example, the main function in your SpectRefl.m file is called using:
someOutputs = SpectRefl(someInputs)
despite the function declaration line reading
function varargout = SpectReflect(varargin )
You can confirm this by putting a disp statement inside the main function in the SpectRefl.m file (and commenting out the SpectRefl function defined after the main function) and calling it using the name SpectRefl. If you also try to define a function SpectRefl inside that file, you have two functions with the same name in the same file. That's not allowed.
To address your other question, it is possible to generate just a .fig file. Go to the Tools menu and select GUI Options. Change the option to generate just the .fig file. However, it's probably going to be more difficult to connect the callbacks for the components in your GUI to the function file you've generated. It's less likely to have the structure the GUI's callbacks expects as the function file generated by GUIDE. Instead, you might want to generate both the function file and the figure file and call your other functions inside the callbacks in the function file.
Weitere Antworten (2)
Walter Roberson
am 29 Mai 2018
The .fig does not exactly store the name of the executable. However, when you use GUIDE to generate callbacks, then the callback it generates calls upon a function that is the same name as the saved fig, and those callbacks are stored as properties of the graphics objects in the .fig .
11 Kommentare
Jan
am 29 Mai 2018
It is a general feature of GUIDE to create the M file with the same name as the FIG file to store the callbacks. The name of the M file is stored in each callback, such that hacking it afterwards is a really tedious task and prone to bugs. Don't do this.
I suppose that such interaction of two M-files blocked correct execution.
Di you have any evidence for this assumption? Of course Matlab can handle multiple functions. It is even a good programming style to keep the GUI and the actual processing separated from each other. This makes it easier to maintain both parts individually.
So if you really observe errors, fix them, but do not shred the interaction between the FIG and the M file.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!