Effacer les filtres
Effacer les filtres

csvwrite file name issue

3 vues (au cours des 30 derniers jours)
lexi11
lexi11 le 4 Mar 2018
Commenté : lexi11 le 4 Mar 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.

Réponse acceptée

Image Analyst
Image Analyst le 4 Mar 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 commentaire
lexi11
lexi11 le 4 Mar 2018
This works perfectly. Thanks very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by