matlab如何给图片取名,如何给图片命名

本文讨论了在 MATLAB 中如何为图像命名和保存的问题,涉及到使用 for 循环动态设置图像标题和保存文件名。同时,文章提到了在 Word 文档中插入并命名图形的操作,包括设置页面边距、标题格式和图形属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本帖最后由 三冗木 于 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一直命名不上,

0c2c68a8a4287caec9636c72e9aa9408.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值