Borrar filtros
Borrar filtros

csvwrite file name issue

3 visualizaciones (últimos 30 días)
lexi11
lexi11 el 4 de Mzo. de 2018
Comentada: lexi11 el 4 de Mzo. de 2018
Hi,
I have a code that generates outputs which I need to save as a csv file. csvwrite works well but I need to generate the filename dynamically. The code is like this:
start=10;
end =50;
info = [output1,output2];% the array that I save my output values
startStr = num2str(start);
endStr = num2str(end);
filenameReal = sprintf('%s to %s !',startStr,endStr);
filename = strtok(filenameReal,'!');
csvwrite([filename],info');
All I want is the filename to appear as '10 to 50.csv'. This needs to be changing with every loop as the start and end changes in every iteration. This code does write a file with name 10 to 50 but it saves as type File, not a .csv file.I can manually change the file type as .csv (in windows explorer) and then I can open the file. My outputs are also saved. But I require the program to save a .csv file as I have a lot of iterations and I do not want to keep manually changing the file type. How do I get the code to save as a .csv file with the filename 10 to 50.csv?
Note: I tried as follows as well:- If I change the last line of the above code as
csvwrite('[filename].csv',info');
it saves a csv file with filename as [filename].csv. That is, this way does not give the file name I require although it saves the outputs in a .csv file.
Thanks in advance.

Respuesta aceptada

Image Analyst
Image Analyst el 4 de Mzo. de 2018
Try it like this:
startingValue = 10;
endingValue = 50; % CAN'T USE end AS A VARIABLE NAME!!!
info = [output1, output2]; % the array that I save my output values
filename = sprintf('%d to %d.csv', startingValue, endingValue );
csvwrite(filename, info');
  1 comentario
lexi11
lexi11 el 4 de Mzo. de 2018
This works perfectly. Thanks very much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by