Borrar filtros
Borrar filtros

How to use variables as filename when saving to a .csv file

4 visualizaciones (últimos 30 días)
JB
JB el 4 de Nov. de 2015
Comentada: Image Analyst el 4 de Nov. de 2015
Hello, I have a program,which takes start date and end date from user,I would like to use the variables as the filename when outputing to a .csv file. I have the following variables :
start_date =[2015, 1, 1];
end_date = [2015, 1, 2];
I want my csv file to be saved in this manner:
output_filename = "start_date " -- "end_date"--"data".csv.
Note: start_date is 1x6 double and end_date is 1x3 double and outputfilename is storing file name to be saved.
Thanks alot in advance.

Respuesta aceptada

Thorsten
Thorsten el 4 de Nov. de 2015
Editada: Thorsten el 4 de Nov. de 2015
output_filename = [datestr(datenum(start_date), 'yyyy-mm-dd') ' -- ' datestr(datenum(end_date), 'yyyy-mm-dd') '--data.csv']
  2 comentarios
JB
JB el 4 de Nov. de 2015
Thanks alot, i was not considering 'datenum' in account. Thanks again..
Image Analyst
Image Analyst el 4 de Nov. de 2015
If you're used to C, you might find it easier to use sprintf() to create the filename.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by