dlmwrite problem
Show older comments
Can someone help put the final touches to the following code. Im attempting to create a .txt file which has a first row specified by 'header' and then attempting to add 'data' from the second row onwards, 'feat1' should be placed above the first column of 'data' and so on. So far I have attempted to import 'header' first and then use append to import 'data'
clear all
outfile= '/path/to/file/output.txt';
data = magic(5);
header={'feat1','feat2','feat3','feat4','feat5'};
dlmwrite(outfile,header,'delimiter','');
dlmwrite(outfile,data,'delimiter','\t','-append');
This doesnt work as all of 'header' appears in the first column and by typing '\t' to try and make it tab delimited it inputs a tab between each letter.
I also tried to wirte a loop for importing 'header':
outfile= '/path/to/file/output.txt';
data = magic(5);
header={'feat1','feat2','feat3','feat4','feat5'};
for i=1:5;
dlmwrite(outfile,header{1,i},'delimiter','');
end
dlmwrite(outfile,data,'delimiter','\t','-append');
This doesn't work as it only stores 'feat5' in the .txt file.
Any advice?
cheers
Accepted Answer
More Answers (0)
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!