如何更改matlab figure左上角的logo图标

如题所述

具体实现方法,其实十分简单,只需要一个函数chgicon.m

该函数用红色文字表示:
function chgicon(h,filename)
%CHGICON changes the figure icon.
%
CHGICON(H,FILENAME) changes the icon of a figure to an image specified by
%
the string FILENAME, where H is a handle to the figure. If the file is not
%
in the current directory or in a directory in the MATLAB path,specify the
%
full pathname of the location on your system. If FILENAME is not a valid
%
image file name, the function just removes the previous icon of the figure.
%
%
Example:
%
h = figure;

%
chgicon(h,'newIcon.png'); % replace 'newIcon.png' with your image

%
% IMPORTANT NOTES:
%
REPLACING THE MATLAB GUI ICON VIOLATES THE LICENSE AGREEMENT
% OF MATLAB. DO NOT USE THIS FUNCTION COMMERCIALLY.
%
%
Han Qun, Sept. 2005
%
Copyright 2005-2006 Han Qun
%
College of Precision Instrument and Opto-Electronics Engineering,
%
Tianjin University, 300072, P.R.China.
%
Email: [email protected]
%
$Revision: 1.0 $
$Date: 2005/12/2 $

if nargin<2

error('MATLAB:chgicon','%s','Too few input arguments!');
end
if nargin >2

error('MATLAB:chgicon','%s','Too many input arguments!');
end
newIcon = javax.swing.ImageIcon(filename);
javaFrame = get(h,'JavaFrame');
javaFrame.setFigureIcon(newIcon);将上面的函数保存在自己要使用的路径下,再调用即可。
调用语句:

h = figure
chgicon(h,'12.jpg');
就可以了。
再推广到GUI上也是一样的,只要在Create Fcn中调用这个函数就可以了:
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
chgicon(hObject,'12.jpg');
温馨提示:答案为网友推荐,仅供参考