How to disable GUI M-file with the same name as FIL file

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Steven Lord
Steven Lord il 8 Giu 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.
  1 Commento
Valeriy
Valeriy il 9 Giu 2018
Thanks a lot, Steven Lord, for your answer.
>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.
This is exactly what I was searching for. I think that different state of such option is reason of differerent reactions on the same code in different computers. Appreciate a lot your comment.

Accedi per commentare.

Più risposte (2)

Walter Roberson
Walter Roberson il 29 Mag 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 Commenti
Valeriy
Valeriy il 3 Giu 2018
Thank you Walter. Do I understand you right, that it should be something like this:
function varargout = SpectReflect(varargin )
[varargout{:}] = SpectRefl(varargin {:});
end % of SpectReflect
function SpectRefl(varargin)
....
end % of SpectRefl
In such construction I have following error message:
Warning: File: SpectRefl.m Line: 6 Column: 10 Function with duplicate name "SpectRefl" cannot be called. The left hand side has varargout{:} inside brackets, which requires that varargout be defined, so that the number of expected results can be computed.
Error in SpectRefl (line 2) [varargout{:}] = SpectRefl(varargin {:});
I have try similar layout like this:
function varargout = SpectReflect(varargin )
[varargout{:}] = SpectRefl(varargin {:});
end % of SpectReflect
function SpectRefl
....
end % of SpectRefl
but error message is the same as previous.
If I remove {:} afer vargout and vargin:
function varargout = SpectReflect(varargin )
[varargout] = SpectRefl(varargin);
end
...
Then I have following error message:
Warning: File: SpectRefl.m Line: 6 Column: 22 Function with duplicate name "SpectRefl" cannot be called. Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
Error in SpectRefl
Could you be more detailed in proposed structure?
Valeriy
Valeriy il 8 Giu 2018
Walter, slightly changing question: Do you have similiar error messages, like in my post of on 1 Jun 2018 at 3:08, while running SpectRefl.m?
As result of our discussion, it seems that now there are no way how to suppress autogenerated M-file. Is it correct?

Accedi per commentare.


Jan
Jan il 29 Mag 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.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by