Matlab更改figure上logo的方法

更新时间:2023-11-19 11:40:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Matlab更改figure上logo的方法

有会员朋友问我能不能修改matlab中figure左上角的logo图标,因此写了这个帖子。答案是肯定的。比如我用这个卡通头像来做新的logo(不用真人的,不侵犯人家肖像权)。

更换过后的效果是:

这样就能使用自己的QQ头像或者照片来作为自己作品的标志了。具体实现方法,其实十分简单,只需要一个函数chgicon.m 该函数用红色文字表示:

functionchgicon(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: junziyang@126.com %$Revision: 1.0 $ $Date: 2005/12/2 $ ifnargin<2

error('MATLAB:chgicon','%s','Too few input arguments!'); end ifnargin>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)

% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called chgicon(hObject,'12.jpg');

结果也是很成功:

本文来源:https://www.bwwdw.com/article/sbxv.html

Top