I have 3 txt files with float data. Each file has 17 rows. First file has 3 columns,other two have 1 column each. I’m trying concatenate those files into one large file-so that i have 5 columns of those file in one file.
I’d doing this :
alldata = [ ];
fid2 = fopen(CombinAttrDiff, 'wt')
NumberOfFiles = 3
for K = 1 : NumberOfFiles %looping over all of the files
thisfile = sprintf('AttrDiff%d.txt',K)
thisdata = load(thisfile);
alldata = [alldata, thisdata];
end
fprintf(fid2, '%f %f %f %f %f\n',alldata);
fclose all
the large output file that is printed out does not concatenate files vertically – all values of first column of 1st file is filling in by rows of the the large output file and then takes second column and conintues filling it in by rows.
what am i doing wrong here? Also is it correct way of concatenating files into one file so that to use it as a matrix later. I want each rows of newly created file to be vector array like this a=[0.32588 0.58425 0.35887 0.00004 0.75544]. I need this so I could compare those rows(arrays) after. I was planning to apply reshape to large file to get matrix after.
I’m newbie in matlab and was trying to make this work a couple of days already.any help wopuld be much apprecited! Thanks!
try
EDIT:
Why this change works?
Matlab stores its arrays in memory in a “column stack” fashion: that is, in memory the second element is
alldata(2,1). So, when you printalldatatofid2matlab orders the elements according to their “in memory” order, regardless of the formatting string you gave.Transposing the array changes the order to suite what you intend.