Dynamic file name with saveas() function

12 次查看(过去 30 天)
Jean
Jean 2012-6-26
Hi,
I am using matlab into a labview program and I need to save figures. I have a variable which contain the name I want to use to save the file but I can't use this variable into the function:
fileName = strcat(numberOfBeams, 'RPM vs Volt');
saveas(gcf, [dirfig, fileName, 'png']);
The code gives an error... But it works if don't use the variable
saveas(gcf, [dirfig, 'RPM vs Volt TEST', 'png']);
Thanks a lot for your help !
  3 个评论
Jean
Jean 2012-6-26
I can't use my program in Matlab directly because it needs my labview variables. But numberOfBeams is a String. So I guess fileName is a String too...
Walter Roberson
Walter Roberson 2012-6-26
What error message is being produced?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2012-6-27
Try this:
folder = dirfig;
baseFileName = sprintf('%d RPM vs Volt.png', numberOfBeams);
fullFileName = fullfile(folder, baseFileName);
saveas(gcf, fullFileName);
% Or even better:
export_fig(fullFileName);
% http://blogs.mathworks.com/pick/2010/05/28/creating-and-exporting-publication-quality-graphics/

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by