csvwrite file name issue
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
lexi11
am 4 Mär. 2018
Kommentiert: lexi11
am 4 Mär. 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.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 4 Mär. 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');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!