I am having trouble writing my matrix to a text file.
10 views (last 30 days)
Show older comments
Matt Mallory
on 2 Nov 2017
Commented: Walter Roberson
on 2 Nov 2017
I am trying to write my variable, textfiledata, to a text file. textfiledata is a nx4 matrix where n changes each iteration. I added labels to each of the four columns using:
header = {'time' 'A1' 'A2' 'INT'};
textfiledata=[header;num2cell(textdataWITHOUTheader)];
I am not sure how to save this matrix to a text file to a designated directory. i tried using save but ran into ASCII errors. I have also tried dlmwrite with no luck.
Thank you for your help.
0 Comments
Accepted Answer
Walter Roberson
on 2 Nov 2017
Edited: Walter Roberson
on 2 Nov 2017
fid = fopen('OutputFileNameGoesHere.txt', 'wt');
tdflip = textfiledata .';
fprintf('%s\t%s\t%s\t%s\n', tdflip{:});
fclose(fid);
6 Comments
Walter Roberson
on 2 Nov 2017
You are doing num2cell on a variable named "textdataWITHOUTheader". That would be a valid call to make on a char array, if the desired result were one character per cell, but I have to wonder whether textdataWITHOUTheader is perhaps numeric instead of a char array? If it is numeric then we would need to format differently.
More Answers (0)
See Also
Categories
Find more on Text Files 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!