csvwrite file name issue
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2018-3-4
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');
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!