How to disable GUI M-file with the same name as FIL file
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Steven Lord
2018년 6월 8일
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.
추가 답변 (2개)
Walter Roberson
2018년 5월 29일
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
Jan
2018년 5월 29일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!