核心方法:通过图像设置命令,直接指定图片的大小。
具体操作:(1) 完成画图及相关设置(字体大小、线宽、图例大小也是正常尺寸),(2) 此时WindowStyle is 'docked',要改为normal,有两种操作:1)在Figure properties——more properties中找到Windowstyle,然后用鼠标改为normal;2)或者直接用命令:set (gcf,'windowstyle','normal')(3) 根据排版要求,确定图片的宽高,例如320*320 像素,然后使用命令set (gcf,'Position',[500,300,320,320])set(gcf,'Units','centimeters','Position',[100 100 98]);% figure的position中的[left bottom width height] 是指figure的可画图的部分的左下角的坐标以及宽度和高度。
(4) 使用copy figure将图片输出到Word1.figure;2.hold on;3.set(gca, 'YTick', [0 : 0.2 : 1]);4.box off;5.set(gca, 'YTickLabel', {'matlab1', 'matlab2', 'matlab3',...6. 'matlab4', 'matlab5', 'matlab6'})1.hold on2.xL=xlim;3.yL=ylim;4.plot(xL,[yL(2),yL(2)],'k',[xL(2),xL(2)],[yL(1),yL(2)],'k')5.box off6.axis([xL yL])1.t=linspace(0,8,100);%%% linspace(X1, X2) generates a row vector of 100 linearlyequally spaced points between X1 and X2.linspace(X1, X2, N) generates N points between X1 and X2.2.a1=axes;%% axes Create axes in arbitrary positions.axes('position', RECT) opens up an axis at the specified locationand returns a handle to it.RECT = [left, bottom, width, height] specifies the location and size of the side of the axis box, relative to the lower-left corner of the Figure window, in normalized units where (0,0) is the lower-left corner and (1.0,1.0) is the upper-right.3.plot(t,sin(t));4.xt=get(gca,'xtick');5.set(gca,'XTick',[],'XColor','w');6.xL=xlim;7.p=get(gca,'Position');8.box off;1.figure2.a2=axes('Position',p+[0,p(4)/2,0,-p(4)/2]); % 确定坐标位置,p为上述3.xlim(xL); %定义x轴坐标4.box off;5.set(gca,'XTick',xt,'Color','None','YTick',[]);简单点儿说吧:xtick是刻度(小竖线);xticklabel 刻度值(竖线下面的数值)。
set(gca,'xtick',-pi:pi/2:pi)这句的意思是:手动设置x轴刻度,-pi到pi之间,每间隔pi/2,划一小竖线;set(gca,'xticklabel',{'-pi','-pi/2','0','pi/2','pi'})这句的意思是:给刚才划上的小竖线,标个数值。
如果你把它改成:set(gca,'xticklabel',{'a','b','c','d','e'}),那么那小竖线下就变成:a,b,c,d,e了。
希望对你有用!findobjfindobj:特殊属性的图形对象语法:1.findobj:findobj返回根对象的句柄和所有子对象(findobj returns handles of the root object and all its descendants without assigning the result to a variable.)2.h = findobj:返回根对象的句柄和所有子对象3.h = findobj('PropertyName',PropertyValue,...)返回所有属性名为‘PropertyName’,属性值为'PropertyValue'的图形对象的句柄。
可以指定多个属性/值对。
4.h = findobj('PropertyName',PropertyValue,'-logicaloperator',PropertyName',PropertyValue,...)-logicaloperator可以取值:-and-or-xor-not等5.h = findobj('-regexp','PropertyName','regexp',...)属性名可以使用正则表达式6.h = findobj('-property','PropertyName')如果存在‘PropertyName’这个属性名,就返回此图形句柄7.h = findobj(objhandles,...)限制搜索范围为objhandles和他们的子图中8.h = findobj(objhandles,'-depth',d,...)指定搜索深度,深度参数'd'控制遍历层数,d为inf表示遍历所有层,d为0等同d='flat'9.h = findobj(objhandles,'flat','PropertyName',PropertyValue,...)'flat'限制搜索范围只能是当前层,不能搜索子图。
如果句柄指向一个不存在的图形,findobj返回一个错误。
findobj正确匹配任何合法属性值,例如:findobj('Color','r')找到所有color值为红的对象。
为了寻找满足指定条件的额handle对象,我们可以使用handle.findobj。
例子:在当前坐标下查找所有直线对象:h = findobj(gca,'Type','line') %gca为当前坐标的句柄查找Label属性设为'foo'和String设为'bar'的所有对象:h = findobj('Label','foo','-and','String','bar');查找String不为'foo'也不为'bar'的所有对象:h = findobj('-not','String','foo','-not','String','bar');h = findobj('String','foo','-and','Tag','button one',...'-and','-not',{'Color','red','-or','Color','blue'})Find all objects for which you have assigned a value to the Tag property (that is, the value is not the empty string ''):h = findobj('-regexp','Tag','[^'']')Find all children of the current figure that have their BackgroundColor property set to a certain shade of gray ([.7 .7 .7]). This statement also searches the current figure for the matching property value pair.h = findobj(gcf,'-depth',1,'BackgroundColor',[.7 .7 .7])Matlab正则表达式正则表达式在处理字符串及文本时显得十分方便,在perl, python等脚本语言,以及java, .net 等平台上都支援正则表达式。
事实上,在MATLAB中也提供了正则表达式的支持。
主要包含三个常用的函数:regexp(), regexpi(), regexprep()。