I am having trouble writing my matrix to a text file.

9 vues (au cours des 30 derniers jours)
Matt Mallory
Matt Mallory 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.

Réponse acceptée

Walter Roberson
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
Matt Mallory
Matt Mallory le 2 Nov 2017
tested the outcome, still no luck.
Thanks for the help though!
Walter Roberson
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by