本帖最后由 三冗木 于 2012-7-14 11:21 编辑
for i=1:2
x=-pi:2*pi/300:pi;
y=sin(x);
h1=gcf;
zft=plot(x,y);
xlabel('声源离地面的高度');
ylabel('频率');
s4=['Distance=' num2str(i) ' M '];
title=(s4);
str=['Distace=' num2str(i) '''Distace=' num2str(i) '.jpg'];
str2=['Distace=' num2str(i) '.fig'];
saveas(gcf,str)
saveas(gcf,str2)
......
end
但是这个title一直命名不上,
QQ截图20120714110401.png (2.44 KB, 下载次数: 6)
2012-7-14 11:04 上传
请各位高手帮忙一下。
看了二楼的解答之后,但是程序还是不能给自动保存的图片来命名,求帮助。下面是自动保存图片的模板,红色部分为一个测试程序,但是title一直命名不上。
function zaiciceshi
%设定测试Word文件名和路径
filespec_user=[pwd '\测试.doc'];
%判断Word是否已经打开,若已打开,就在打开的Word中进行操作,
%否则就打开Word
try
Word = actxGetRunningServer('Word.Application');
catch
Word = actxserver('Word.Application');
end;
%设置Word属性为可见
set(Word, 'Visible', 1);
%返回Word文件句柄
documents = Word.Documents;
%若测试文件存在,打开该测试文件,否则,新建一个文件,并保存,文件名为:测试.doc
if exist(filespec_user,'file');
document = invoke(documents,'Open',filespec_user);
else
document = invoke(documents, 'Add');
document.SaveAs(filespec_user);
end
content = document.Content;
selection = Word.Selection;
paragraphformat = selection.ParagraphFormat;
%页面设置 (上下左右边距)
document.PageSetup.TopMargin = 60;
document.PageSetup.BottomMargin = 45;
document.PageSetup.LeftMargin = 45;
document.PageSetup.RightMargin = 45;
%设定内容起始位置和标题
%set(content, 'Start',0);
title='测 试 文 件';
set(content, 'Text',title);
set(paragraphformat, 'Alignment','wdAlignParagraphCenter'); % 居中
% set(paragraphformat, 'Alignment','wdAlignParagraphLeft'); % 居左
% set(paragraphformat, 'Alignment','wdAlignParagraphRight'); % 居右
%设定标题字体格式
rr=document.Range(0,10);
rr.Font.Size=18; % 字体大小设置
rr.Font.Bold=4; % 设置字体加粗
%设定下面内容的起始位置(将光标放在最后边)
end_of_doc = get(content,'end');
set(selection,'Start',end_of_doc);
%另起一段
selection.TypeParagraph;
%如果当前工作文档中有图形存在,通过循环将图形全部删除
%shape=document.Shapes;
%shape_count=shape.Count;
%if shape_count~=0;
%for i=1:shape_count;
%shape.Item(1).Delete;
%end;
%end;
%程序部分
for i=1:2
x=-pi:2*pi/300:pi;
y=sin(x);
h1=gcf;
zft=plot(x,y);
s4=['Distance=' num2str(i) ' M '];
xlabel('声源离地面的高度');
ylabel('频率');
title(s4);
str=['Distace=' num2str(i) '''Distace=' num2str(i) '.jpg'];
str2=['Distace=' num2str(i) '.fig'];
saveas(gcf,str)
saveas(gcf,str2)
%将图形复制到粘贴板
hgexport(h1, '-clipboard');
%将图形粘贴到当前文档里,并设置图形属性为浮于文字上方
% selection.Range.PasteSpecial;
%将图形粘贴到当前文档里,并设置图形属性为嵌入式
selection.Range.Paste;
% shape.Item(1).WrapFormat.Type=3;
% shape.Item(1).ZOrder('msoBringInFrontOfText');
%删除图形句柄
delete(zft);
end