フィルターのクリア

csvwrite file name issue

3 ビュー (過去 30 日間)
lexi11
lexi11 2018 年 3 月 4 日
コメント済み: lexi11 2018 年 3 月 4 日
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.

採用された回答

Image Analyst
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');
  1 件のコメント
lexi11
lexi11 2018 年 3 月 4 日
This works perfectly. Thanks very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by