网上常用的方法: if ~isdeployed newIcon=javax.swing.ImageIcon('.\pic\iap.jpg'); else newIcon=javax.swing.ImageIcon('iap.jpg'); end jFrame = get(hObject,'javaframe'); jFrame.setFigureIcon(newIcon); 运行后warning: Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on the MathWorks Web site. 新方法 ( http://www.mathworks.com/matlabcentral/answers/7313-change-guide-icon ): if ~isdeployed newIcon=javax.swing.ImageIcon('.\pic\iap.jpg'); else newIcon=javax.swing.ImageIcon('iap.jpg'); end jFrame = get( handle (hObject),'javaframe'); jFrame.setFigureIcon(newIcon);
在博文《 Matlab :学习 GUI (一个简单的例子)》( http://blog.sciencenet.cn/blog-200199-870822.html) 中 介绍的方法是完全用代码来建立一个 GUI ,实际上 Matlab本身有 一个设计 GUI 的交互系统—— GUIDE ,用户可以使用该系统更方便的建立自己的 GUI. 本文将介绍使用 GUIDE 时常常遇到的几个问题。 本文将通过一个简单的例子来说明问题,读者朋友们可以边看边操作。在 command line 输入 guide 回车,打开 Layout Editor. 建立一个空白的模板( Blank GUI ),建立一个 push button ,将“ String ”改为“ Close ”, save 并将文件名命名为 test ,如下图: save 后, Matlab 会生成两个文件 test.M 和 test.fig ,打开 test.M ,如下: function varargout = test(varargin) % Begin initializationcode - DO NOT EDIT gui_Singleton = 1; gui_State = struct( 'gui_Name' , mfilename, ... 'gui_Singleton' , gui_Singleton, ... 'gui_OpeningFcn' , @test_OpeningFcn, ... 'gui_OutputFcn' , @test_OutputFcn, ... 'gui_LayoutFcn' , ); if nargin ischar(varargin{1}) gui_State.gui_Callback =str2func(varargin{1}); end if nargout =gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code- DO NOT EDIT % --- Executes justbefore test is made visible. function test_ OpeningFcn (hObject,eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); % --- Outputs from thisfunction are returned to the command line. function varargout = test_ OutputFcn (hObject,eventdata, handles) varargout{1} = handles.output; % --- Executes on buttonpress in pushbutton1. function pushbutton1_ Callback (hObject,eventdata, handles) 生成的 M 文件的结构主要由三个子函数构成: _OpeningFcn ,这个函数是在 GUI 界面出现以前 Matlab 在后台运行的, GUI 设计者可以在这个函数内完成数据初始化设置、 GUI 的界面的控制和调整等工作。 _OutputFcn 函数是 M 文件最后运行的函数,主要是为了输出运行结果。 _Callback 函数用于控制 component 的触发行为,比如说用户按下界面的按钮后,该按钮应该执行什么命令。我们这个例子设计的是按下“ Close ”按钮后, GUI 界面关闭,因此需要在 function pushbutton1_ Callback (hObject, eventdata, handles) 后面加上: delete(handles.figure1); 下面我们开始借助这个简单的例子,讲一讲新手在应用 GUIDE 时常见的三个问题: 问题一: figure Name 和 figure tag 弄混了。 Figure Name 指的是 M 文件和 Fig 文件的 name ,即本例中的 test. Tag 指的是设计 GUI 界面时为每个 component 所指定的标签,也是程序中唯一的可以识别 component 的名字, GUI 的面板也是一个 component ,有自己的 tag ,即本例中默认的 figure1. 弄混 figure tag 和 figure name 的例子如下: 错误代码: function pushbutton1_Callback(hObject, eventdata, handles) delete(handles.test); 当运行错误代码时, Matlab 会提示找不到 handles 中的 test 变量,因为 handles 只是存储 component 的句柄,每个句柄是以 tag 来命名的: ??? Reference to non-existentfield 'test'. Error in ==testpushbutton1_Callback at 81 delete(handles.test); 问题二: uiwait 在逻辑上与 uiresume 不配对。 还是上面的例子,如果再增加一个功能,等用户按下“ Close ”按钮后,在屏幕输出“ OK ”,否则不输出。为实现该功能,在 test_ OpeningFcn 的 guidata 语句后增加: % UIWAIT makes test waitfor user response (see UIRESUME) uiwait(handles.figure1); 在 test_OutputFcn 的 varargout{1} 语句后添加: delete(handles.figure1); 将 pushbutton1_Callback 中的 delete(handles.figure1) 删除,并添加: disp('OK'); uiresume(handles.figure1); 运行后,用户点击“ Close ”按钮,一切正常。 可是,当用户不点击“ Close ”而是直接关闭窗口时,程序提示 OutputFcn 输出错误: 出现该错误的原因是:当用户直接关闭窗口时,所有在内存中的变量都被清楚,程序在执行到 OutputFcn 是已没有变量可以赋值给结构变量 varargout{1} 了。为了改正该错误,需要添加 _CloseRequestFcn 函数: % Executes when userattempts to close figure1. function figure1_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future versionof MATLAB % handles structure with handles and user data (seeGUIDATA) if isequal(get(hObject, 'waitstatus' ), 'waiting' ) % TheGUI is still in UIWAIT, us UIRESUME uiresume(hObject); else % TheGUI is no longer waiting, just close it delete(hObject); end 可是,如果直接将上述代码复制到 test.m 文件中,保存,运行,关闭窗口时,同样会出现上述 OutputFcn 输出错误,这个就涉及到下面第三个问题。 问题三: Layout Editor 的设置和 M 文件不同步。 为解决上述问题,可打开 figure1 的 Property Inspector, 注意到 CloseRequestFcn 一栏,显示的是 closereq ,点击以下旁边的图片,变为: 这说明两者已经同步,此时可以放心的运行程序了。
GUI是graphical user interface的简称,说白了就是我们常见的对话框。 下面是Matlab提供的一个简单例子,博主加上了自己的注释,供参考。 function hpopup=simple_gui2 % SIMPLE_GUI2 Select a data set from the pop-up menu, then % click one of the plot-type push buttons. Clicking the button % plots the selected data in the axes. % Initialize and hide the GUI as it is being constructed. % 生成图形面板,'visible'('on'\'off')是/否显示面板,'position' % 定义面板在显示屏上的位置(left,距离屏幕左边界的距离;bottom,距离屏幕下边界的距离) % 以及面板的大小(width,面板宽;height,面板高,不包括title bar, menu bar, tool bars, and outer edges) % The left and bottom elements can be negative on systems that have more % than one monitor. 缺省单位是pixels. f = figure('Visible','off','Position', ); %%%%%%%%%与figure相关的控制语句%%%%%%%%%%%%%% % Assign the GUI a name to appear in the window title. set(f,'Name','Simple GUI') % Move the GUI to the center of the screen. movegui(f,'center') % Make the GUI visible. set(f,'Visible','on'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Construct the components. % 利用uicontrol添加push button. 'Style',添加对象类型,还可添加pop-up menu,static text等类型. % 'String'('Text'),push button 上要显示的文字. 'position'同figure. % 'Callback',当用户按下button或选择pop-up menu时,Matlab执行的函数. hsurf = uicontrol('Style','pushbutton',... 'String','Surf','Position', ,'Callback',{@surfbutton_Callback}); hmesh = uicontrol('Style','pushbutton',... 'String','Mesh','Position', ,'Callback',{@meshbutton_Callback}); hcontour = uicontrol('Style','pushbutton',... 'String','Contour','Position', ,'Callback',{@contourbutton_Callback}); hpopup = uicontrol('Style','popupmenu',... 'String',{'Peaks','Membrane','Sinc'},... 'Position', ,'Callback',{@popup_menu_Callback}); htext = uicontrol('Style','text','String','Select Data',... 'Position', ); % 利用uicontrol添加static text ha = axes('Units','pixels','Position', ); % 添加坐标轴以显示输出结果,注意用'Units'指定Position的单位是'pixels',以与其它对象保持一致. align( ,'Center','None'); % 水平中心对齐push button、pop-up mesh以及static text,垂直方向不变动 % align(HandleList,'HorizontalAlignment','VerticalAlignment') % Initialize the GUI. % Change units to normalized so components resize automatically. set( ,'Units','normalized'); % Make the GUI behave properly when it is resized by changing the component % and figure units to normalized. This causes the components to resize when the GUI is resized. % Normalized units map the lower-left corner of the figure window to (0,0) % and the upper-right corner to (1.0, 1.0). % 将面板放大的时候,各对象(axes\buttons\pop-up menu\static text等)同比例放大 % Generate the data to plot. peaks_data = peaks(35); membrane_data = membrane; = meshgrid(-8:.5:8); r = sqrt(x.^2+y.^2) + eps; sinc_data = sin(r)./r; % Create a plot in the axes. current_data = peaks_data; surf(current_data); % Pop-up menu callback. Read the pop-up menu Value property to % determine which item is currently displayed and make it the % current data. This callback automatically has access to % current_data because this function is nested at a lower level. % 当用户触发popup menu时,句柄hpopup的值传给source % str=get(source, 'String') str是3*1的cell,即pop-up menu的string{'Peaks','Membrane','Sinc'} % val = get(source,'Value') val的值记录了用户触发了那个按钮,1对应'peaks',2对应的是'Membrane',3对应的是'Sinc' function popup_menu_Callback(source,eventdata) % Determine the selected data set. str = get(source, 'String'); val = get(source,'Value'); % Set current data to the selected data set. switch str{val}; case 'Peaks' % User selects Peaks. current_data = peaks_data; case 'Membrane' % User selects Membrane. current_data = membrane_data; case 'Sinc' % User selects Sinc. current_data = sinc_data; end end % Push button callbacks. Each callback plots current_data in the % specified plot type. function surfbutton_Callback(source,eventdata) % Display surf plot of the currently selected data. surf(current_data); end function meshbutton_Callback(source,eventdata) % Display mesh plot of the currently selected data. mesh(current_data); end function contourbutton_Callback(source,eventdata) % Display contour plot of the currently selected data. contour(current_data); end end
安装了好几次,这次终于成功了。 1) Start the Perl Package Manager GUI from the Start menu. 2) Go to Edit Preferences and click the Repositories tab. Add a new repository for each of the following (note the difference based on the perl version). NOTE - The DB_File installed with ActivePerl 5.10 and above is a stub (i.e. it does not work). The Trouchelle database below has a working DB_File. Repositories to add Name perl 5.8 perl 5.10 BioPerl-Regular Releases http://bioperl.org/DIST http://bioperl.org/DIST BioPerl-Release Candidates http://bioperl.org/DIST/RC http://bioperl.org/DIST/RC Kobes http://theoryx5.uwinnipeg.ca/ppms http://cpan.uwinnipeg.ca/PPMPackages/10xx/ Bribes http://www.Bribes.org/perl/ppm http://www.Bribes.org/perl/ppm Trouchelle http://trouchelle.com/ppm http://trouchelle.com/ppm10 tcool http://ppm.tcool.org/archives/ NA 3) Select View All Packages . 4) In the search box type bioperl. (在英文输入状态下输入,不要急于按enter键) 5) Right click the latest version of Bioperl available and choose install. (Note for users of previous Bioperl releases: you should not have to use the Bundle-BioPerl package anymore.) 5a) From bioperl 1.5.2 onward, all 'optional' pre-requisites will be marked for installation. If you see that some of them complain about needing a command-line installation (eg. XML::SAX::ExpatXS), and you want those particular pre-requisites, stop now (skip step 6) and see the 'Command-line Installation' section. 6) Click the green arrow (Run marked actions) to complete the installation.
void QCoreApplication:: processEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) Processes all pending events for the calling thread according to the specified flags until there are no more events to process. You can call this function occasionally when your program is busy performing a long operation (e.g. copying a file). In event you are r unning a local loop which calls this function continuously , without an event loop, the DeferredDelete events will not be processed. This can affect the behaviour of widgets, e.g. QToolTip , that rely on DeferredDelete events to function properly. An alternative would be to call sendPostedEvents() from within that local loop. Calling this function processes events only for the calling thread. zz: http://doc.qt.nokia.com/4.7-snapshot/qcoreapplication.html#processEvents
Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler This article will show you how to build Qt, the popular C++ framework from Nokia, so that it is both small and, if you prefer, available for static linking . Your Qt applications will be smaller, possibly faster, and can be distributable as a single executable. Also answered: How small can Intel’s C++ compiler make a large library? How does Microsoft fare? Three compilers (settings tuned for small file output) and their resulting code size is compared. A nice table of contents so that you can see what you’re getting into: * optional Download the latest Qt source code and put it in its own directory. *Modify the compiler flags for use when building Qt. Open a command-line window for your compiler. Configure. Compile. *If you want to use static linking, modify your Qt project. A few things to keep in mind before we get started: Before getting started, you may wish to install a separate compiler.The full Qt SDK comes with G++3 as of this writing (G++ is the C++ compiler that comes with GCC). It works, but G++4 generates better code. I recommend the TDM release . Microsoft Visual Studio Intel’s compiler are also very capable. This article covers them all. G++ and the Intel compiler are compatible. Either compiler can link to libraries built with the other compiler. Microsoft’s C++ compiler is incompatible with the other two, so if you build Qt with it, you are stuck with Microsoft’s compiler for the whole project. This isn’t necessarily bad. Visual C++ is a fine compiler, and finishes compiling Qt noticeably faster than the other two. GCC is available free of charge, source code included. Microsoft’s compiler is available for free in their “ Express edition “. It is more or less fully functional. Intel’s compiler, however, is only available free of charge on the Linux platform, and even then only for non-commercial software development. That said, it is widely thought of as producing the fastest code. With that out of the way, let’s begin: Download the latest Qt source code and put it in its own directory. You can get the entire SDK or just the source code . Either way, each compilation should be in a separate folder. * Modify the compiler flags for use when building Qt. You’ll be changing one line of the file “make.conf” in the “mkspecs” folder. If Qt in the “C:\Qt” folder, for example, then the file is “C:\Qt\mkspecs\ COMPILER \make.conf”, where COMPILERis : “ win32-g++ ” for GCC “ win32-icc ” for the Intel compiler “ win32-msvc2008 ” for the Microsoft compiler (replace 2008 with the year of release).In all three cases, you will edit the line: “ QMAKE_CFLAGS_RELEASE = “, changing the contents after the equals sign to the following: For GCC: -Os -momit-leaf-frame-pointer For ICC: -Os -Oy For VC++: -O1 -Og -GL -MD For example, my ICC line shows: “ QMAKE_CFLAGS_RELEASE = -Os -Oy ” You may wish to add other optimizing flags as well. See your compiler’s documentation. Open a command-line window appropriate for your compiler . GCC: Open the command prompt (Start – Run – “cmd”), then run “mingwvars.bat”. For example, if GCC is installed in “c:\MinGW”, then enter the command: “ c:\MinGW\mingwvars.bat “ Microsoft Visual Studio : Look for the “Visual Studio 2008 Command Prompt” entry in your start menu. It is usually found under “Programs\Microsoft Visual Studio 200 X \Visual Studio Tools\”. The Express versions should be similar. Alternatively, search your hard drive for “vcvarsall.bat” and from that folder, run “ vcvarsall.bat x86 ” from the command line. Intel compiler : Similar to Visual Studio, an icon is provided in your start menu, usually in: “Programs\Intel(R) Software Development Tools\Intel(R) C++ Compiler x.y.z “. Alternatively, find iclvars.bat and from that folder, run “ iclvars.bat ia32 “ Configure Qt. Change to the Qt folder. For example, type cd C:\Qt\4.6.3-msv c if you unzipped Qt to C:\Qt\4.6.3-msvc.This folder should have configure.exe within. Run the following long command: configure -release -nomake examples -nomake demos -no-exceptions -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite Add “ -platform win32-??? ” for your compiler. Replace “???” with the name of your compiler, same as in step 2. You can also look for your compiler’s name in the Qt\mkspecs folder. For example, a Microsoft Visual Studio 2008 user would use “ -platformwin32-msvc2008 “. Add “ -static ” if you are compiling for static linking (libraries included in your .exe rather than as separate files. This mostly applies to qtcore4.dll and qtgui4.dll ) Add any static functionality your application needs., if you are compiling static For example, -qt-libjpeg -qt-zlib -qt-libpng for JPEG image, ZIP compression, and PNG (which also needs zlib) respectively. See How to Statically Link Qt4 . Remove “ -no-exceptions -no-stl -no-rtti ” if you need those C++ features. Note that with -no-stl , you are still able to use the ST L, but Qt will not have built-in convenience functions to, for example, set a QVector equal to a C++ vector. That is, you will have to do so manually. Replace “ -release ” with “ -debug-and-release ” if this will be your debug install, too. Do not use -static . The remaining “ -no- foo ” options disable various features. See the output of “ configure –help ” for documentation. You can write this to a file with “ configure –help options.txt “. Compile Qt . After step 4, you will be informed of which command starts the actual compile (usually mingw32-make or nmake ). (static only) Configure your project for use of the static library. It’s the size that counts and how you use it. When working towards making Qt (and therefore your projects) small, it is important to have some idea of what each compiler can do. I will compare the sizes of QtCore4.dll (core Qt functionality) and QtGui4.dll (Graphical interface libraries and operating system interface). These two files that are fairly representative of size scaling among Qt libraries, and also happen to be the two most common files needed by Qt applications. Interpretation: ICC’s code size is about the same as GCC’s unoptimized. The sum of both file’s sizes is 11.38MB on both compilers. With appropriate settings, GCC’s compiled Qt code size drops more than 40%, from 11.38MB to only 6.63MB combined. Microsoft Visual C++ handily beats the other compilers, with a library size less than half of ICC’s and about 15% smaller than GCC’s best effort.( Edit : Arik notes that this compilation is still dependent on Microsoft’s msvcrt XX .dll . See his comment below regarding how to eliminate this dependency. This may change the size of your application). Additionally, Microsoft’s compiler finished the job in about 1/5 the time of ICC and about 1/3 the time of GCC Optimized. I actually ran it twice because I thought it may have aborted without error, because the time difference was so substantial. Update : I’ve compiled CNB ImageGuide to provide a real application size example. Using G++, executable size is 5.8MB. Using Microsoft C++ 2008 and Arik’s suggestion, it is 3.56MB, or about a 60% difference. I’d like to welcome theories as to why the difference is so substantial. However : This does not take into account the performance of the resulting libraries , with Intel likely taking the lead. ICC is designed for absolute performance, not small code size. MSVC is not available on most platforms supported by Qt. The author is far more familiar with the compiler flags for G++ than for the other two compilers. It is possible that a particular combination of options will significantly change the results. I hope this has been helpful and informative. Communicate any feedback, good or bad, in the comments section. Repeatability Everyone is welcome to try to repeat, improve upon, or dispute my results. The settings used follow. Intel Compiler 11 cflags : -Os -Oy Qt configuration : -release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-icc Microsoft Visual C++ 2008 cflags : -O1 -GL -MD Qt configuration : -release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-msvc2008 GCC 4.4.1 default (TDM release 2) cflags : -O2 Qt configuration : -release -nomake examples -nomake demos -platform win32-g++ GCC 4.4.1 Optimized cflags : -Os -mpreferred-stack-boundary=2 -finline-small-functions -momit-leaf-frame-pointer Qt configuration : -release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-g++ Edit 27 Jan 2010: Memory footprint data for both executables (GCC and Microsoft compiled) Memory footprint - Qt static compiled with GCC 4.4 Memory footprint - Qt static compiled with MS Visual Studio 2008 zz: http://www.formortals.com/build-qt-static-small-microsoft-intel-gcc-compiler/
He=plot(0,0,'c.','markersize',24); hold on ezplot('0.0508*x^2-0.0702*x*y+0.0381*y^2-0.4531*x+0.2643*y+1', ) t=linspace(0,2*pi,100); set(gcf,'doublebuffer','on'); axis( ) k=1; i=1; while k s=get(gcf,'currentkey'); if strcmp(s,'space'); clc;k=0; end i=i+1; xe=5.9*cos(t(i))+5.67; ye=5.9*sin(t(i))+1.8; set(He,'xdata',xe,'ydata',ye); pause(0.1); end