Filter löschen
Filter löschen

How to customize print file name with function input

6 Ansichten (letzte 30 Tage)
Ivy Chen
Ivy Chen am 8 Nov. 2017
Kommentiert: Ivy Chen am 13 Nov. 2017
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');___

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Nov. 2017
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 Kommentare
Walter Roberson
Walter Roberson am 9 Nov. 2017
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 am 13 Nov. 2017
Great, thanks! I have updated the code accordingly.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by