Convert Array to Text File
Show older comments
Hello all, I am trying to determine how to convert a 145x3 array of doubles into a text file of a specific format. I seem to be having trouble with the strategies I've taken so far and was wondering if there any additional suggestions.
I need my output text file to look like this:
Jonswap.txt
< waveheight > < waveperiod > < mainangle >
< waveheight > < waveperiod > < mainangle >
< waveheight > < waveperiod > < mainangle >
I have my variables stored in a 145x3 array as mentioned above. The first column is mainangle the second is waveheight and the third is waveperiod. Each row is a 1 hour time step. I need to write text file that prints each row out as shown above (without the angle brackets), and then moves to the next row.
Any suggestions?
Here is my current attempt:
output = evalc(waveparams_m);
fileID = fopen('jonswap.txt','w');
for i = 1:size(waveparams_m,3)
fprintf(fileID, [output, ' 3.300 20.0000 3600 1' ]);
fprintf(fileID, '\n')
end
fclose(fileID);
type jonswap.txt
The additional values at the end ('3.300 20.0000 3600 1') are standard for each time step and do not change.
Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!