フィルターのクリア

How to customize print file name with function input

6 ビュー (過去 30 日間)
Ivy Chen
Ivy Chen 2017 年 11 月 8 日
コメント済み: Ivy Chen 2017 年 11 月 13 日
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]
Ivy Chen
Ivy Chen 2017 年 11 月 13 日
Great, thanks! I have updated the code accordingly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace 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