Borrar filtros
Borrar filtros

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

60 visualizaciones (últimos 30 días)
L'O.G.
L'O.G. el 30 de Mzo. de 2022
Comentada: Les Beckham el 30 de Mzo. de 2022
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 comentario
Geoff Hayes
Geoff Hayes el 30 de Mzo. de 2022
@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);

Iniciar sesión para comentar.

Respuesta aceptada

Les Beckham
Les Beckham el 30 de Mzo. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by