필터 지우기
필터 지우기

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 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