MATLAB Answers

Text file has no space between elements - Filename

2 views (last 30 days)
I am trying to save a matrix (8760 x 1) to a text file. This is my code:
However, the generated text file has no space between the elements. Therefore, I get something like this:
5.845.845.655.776. etc.
Any ideas? Also, how can I insert a string variable into the filename of the .txt file? e.g. totalenergy_'X'.txt where X is a variable.

Accepted Answer

Image Analyst
Image Analyst on 5 May 2017
That's where the lines split, and you're probably looking at it in notepad or something. Double-click on it in the Current Folder panel of MATLAB and you'll see it looks normal.
Image Analyst
Image Analyst on 5 May 2017
Use sprintf() and fullfile():
folder = 'C:\wherever';
baseFileName = sprintf('totalenergy_%d.txt', X) % where X is an integer.
baseFileName = sprintf('totalenergy_%.4f.txt', X) % where X is a double
baseFileName = sprintf('totalenergy_%s.txt', X) % where X is a string
fullFileName = fullfile(folder, baseFileName);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!