필터 지우기
필터 지우기

How to append a string to a filename when saving a file?

조회 수: 60 (최근 30일)
L'O.G.
L'O.G. 2022년 3월 30일
댓글: Les Beckham 2022년 3월 30일
How do I append a string to the filename and save the file in the case of saveas and save? The following isn't quite right, so I'd appreciate some insight.
[~,f,ext] = fileparts(files(id).name); % extract file name without original extension
% do some calculations and generate a plot based on the original file
str_saveas = sprintf(str_saveas,f);
saveas(fig,'str_saveas','png')
And similarly, for the save function.
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2022년 3월 30일
@O.G. what is
str_saveas
? If you just want to append two string variables together, you could use the square brackets as
str_saveas = [str_saveas f];
sprintf would be used more like
str_saveas = sprintf('%s%s', str_saveas, f);

댓글을 달려면 로그인하십시오.

채택된 답변

Les Beckham
Les Beckham 2022년 3월 30일
This should get you closer to what you want to do
[~,f,ext] = fileparts(files(id).name); % extract file name without original extension
% do some calculations and generate a plot based on the original file
str_append = 'text_that_you_want_to_add';
str_saveas = sprintf('%s_%s', f, str_append); % add the appended string to the original filename
saveas(fig, str_saveas, 'png') % note no quotes on the filename since it is a variable

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by