MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] Matlab中的sendmail功能,请各位高手指点,不胜感激。 (https://www.labfans.com/bbs/showthread.php?t=10209)

wt_v90 2009-11-16 17:44

Matlab中的sendmail功能,请各位高手指点,不胜感激。
 
在运用matlab创建文件的时候,文件名是自动定义的,如下:

col = 5;
for i = 1 : col
filepath='C:\Documents and Settings\output\';
fid=fopen([filepath 'Test' num2str(i) '.txt'],'wt');
format = '%s\r\n';
for j = 1 : length(results{1,col})
data = strvcat(results{1,i}{j});
fprintf(fid,format,data');
end
fclose(fid);

所生成的文件名是 Test1, Test2, ... Test5
之后把生成的文件用sendmail发送。发送邮件的时候,同样希望sendmail可以自动识别文件名,如下:

subject = 'Test Title';
message = 'Test messgae';
to = {'[email protected]'};
attachment = {'C:\Documents and Settings\output\Test' num2str(i) '.txt'};
sendmail(to, subject, message, attachment);
end

错误显示不能打开文件:Test。
有没有什么办法可以让sendmail识别变换的附件名? 请高手帮忙!谢谢。

wt_v90 2009-11-16 18:28

回复: Matlab中的sendmail功能,请各位高手指点,不胜感激。
 
问题已经解决,谢谢大家的关注。
我简单解释一下问题出在哪里。

matlab中大括号创建的是元胞数组字符串和自定义变量是不联系的,如果想把它们联系起来,应该用中括号。只要把
attachment = {'C:\Documents and Settings\output\Test' num2str(i) '.txt'};
改成
attachment = {['C:\Documents and Settings\output\Test' num2str(i) '.txt']};
就可以了。


所有时间均为北京时间。现在的时间是 06:19

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.