How to customize print file name with function input

6 次查看(过去 30 天)
I have a function including following input items: Filepath, NsperBatch, K. And I would like to use them as part of filename when saving a plot:
print('Magnitude (dB) vs Time vs Frequency Collected in %d RF_bin with Batch %d Avg %d',Filepath,NsperBatch,K,'-dpng');
Receiving some errors as followings:
Error using checkArgsForHandleToPrint
Handle input argument contains nonhandle values.
Error in checkArgsForHandleToPrint
Error in print>LocalCreatePrintJob (line 216)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in processAverna (line 93)
print('Magnitude (dB) vs Time vs Frequency Collected in %d RF_bin with Batch %d
Avg %d',Filepath,NsperBatch,K,'-dpng');___

采纳的回答

Walter Roberson
Walter Roberson 2017-11-8
filename = sprintf('Magnitude (dB) vs Time vs Frequency Collected in %d RF_bin with Batch %d Avg %d',Filepath,NsperBatch,K);
print(filename , '-dpng')
  3 个评论
Walter Roberson
Walter Roberson 2017-11-9
I notice that you have a variable named FilePath but you use a %d format specifier for it. That is confusing: I would have expected a %s format specifier.
If you have a qualified file name and want to get just the last part of the name, then
[~, basename, ext] = fileparts(filePath);
then use either basename by itself or [basename ext]

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by