I am having trouble writing my matrix to a text file.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matt Mallory
le 2 Nov 2017
Commenté : Walter Roberson
le 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 commentaires
Réponse acceptée
Walter Roberson
le 2 Nov 2017
Modifié(e) : Walter Roberson
le 2 Nov 2017
fid = fopen('OutputFileNameGoesHere.txt', 'wt');
tdflip = textfiledata .';
fprintf('%s\t%s\t%s\t%s\n', tdflip{:});
fclose(fid);
6 commentaires
Walter Roberson
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!