How to save MAT files into a text file

I have an automated process where by I save my outputs into various MAT files. I wish now to combine these into one text file with the various MAT files making up the different columns. I am not sure how to do it this an automated way. As I have many outputs I would rather not do this myself at the end

Answers (1)

How to process a sequence of files:
And for writing to text:
doc csvwrite

3 Comments

Thank you so much, the main thing I am struggling with though is how to get multiple variable and have them as different columns of the one text file so for example I have 3 variable that I am saving
Mean weight Weight COV
so for one I assume I would simply code the following;
numfiles = 7;
mydata = cell(1,numfiles);
for k = 1:numfiles
myfilename= sprintf('MeanWeight%d.txt',k);
mydata {k} = csvwrite('Overall.txt',myfilename);
end
However I would I import the other variable into the 2nd and 3rd columns of the same text file
Thanks guys, sorry I dint realise I had put it as an aswer instead of a comment
This code does not really make much sense, and you should reivew the link that Sean de Wolski gave in their Answer.
When you read the documentation for csvwrite it states on the very first line: csvwrite(filename,M) writes matrix M into filename as comma-separated values
So what are you hoping to achieve with your code
csvwrite('Overall.txt',myfilename)
where myfilename is a string (containing a filename) ? Where is the numeric matrix that the function requires?
Indeed where is the "other variable" that you are talking about? Which columns? Of what? If each file 'MeanWeight%d.txt contains data that you wish to import, then you need to import it first, before it can be saved again in a CSV file. Examples of this can be found in that link.
Also note that currently every iteration of the loop completely overwrite the file Overall.txt. This is probably not what you intended.

Sign in to comment.

Categories

Find more on Scripts in Help Center and File Exchange

Asked:

on 24 Feb 2015

Edited:

on 25 Feb 2015

Community Treasure Hunt

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

Start Hunting!