필터 지우기
필터 지우기

Run a function when a GUI fig is opened?

조회 수: 3 (최근 30일)
Campbell
Campbell 2012년 5월 4일
Is it possible to automatically run a function when a GUI (fig) is opened? I.e. is there a property of the fig class that would do this? I would like to construct the controls differently depending on the environment, e.g. Windows vs. Linux, which specific files are in the system search path, etc. Thanks, Campbell

채택된 답변

Image Analyst
Image Analyst 2012년 5월 5일
Use GUIDE. Then look at the m-file it creates. In there you'll find a function called yourgui_OpeningFcn(). You can place your code there and it will automatically get run when you launch your GUI. Check this out if you want to get up to speed fast: http://www.mathworks.com/matlabcentral/fileexchange/24224 It has a basic framework that is a good starting point for you to insert your code into various buttons, checkboxes, etc.
  댓글 수: 2
Campbell
Campbell 2012년 5월 5일
Thanks. I had not been using GUIDE to create the GUI, but rather was using code to set up the controls. Now that I understand the reference to opening function, it is clear what I need to do.
What is not clear yet is how to implement another feature that I had in mind, namely to allow the user to save multiple versions of the fig file after they have set the various control to different custom values.
Image Analyst
Image Analyst 2012년 5월 5일
In Guide do File->Save As... Don't do it any other way, like copying things in Windows Explorer, or you'll regret it. If you do it via GUIDE, it will automatically rename all your callbacks for the new name.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jakob Sørensen
Jakob Sørensen 2012년 5월 4일
You can run it through the GUI opening function, or do you mean for any figure which is opened?
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 5월 4일
Is this for GUIDE? GUIDE .fig files are not designed to be used independently of the .m file of the same name. The .m file contains a GUI open function, which is the place that you would normally put a call to the routine to make OS-specific adjustments.
.fig files that contain code are not designed to run any function when they are opened.
Jakob Sørensen
Jakob Sørensen 2012년 5월 5일
Normally what you do is make a GUI (using Guide), which can be run by typing its name in the command prompt (assuming that you're in the correct folder). Once in the GUI, you're free to make controls for almost everything...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by