Facing problems in writing data to a .dat file?
Afficher commentaires plus anciens
Hi everyone!
After extracting data from the attached datapp.txt file when I tried to write it again in a output.dat file, I am not getting the results the way I want. I guess its because the variables are read as a character array. However, I don't know how to deal with it. The written output.dat file should be in the following format.....
TS_sec gage5 gage10 gage13 gage19
0.00000000e+00 3.74000000e+00 4.62000000e+00 -6.32000000e+00 3.70000000e+00
3.62884792e+03 4.06626222e+00 4.94714691e+00 -6.02841756e+00 4.02629196e+00
7.37845996e+03 3.70195900e+00 4.58459573e+00 -6.37805257e+00 3.66177872e+00
I have tried the following code.........Could you guys please help me in this regard. Thanks....## My Problem is in writing output files in the above mentioned format.
function main
A = regexp(fileread('datap.dat'),'\n','split');
Whichline = find(~cellfun('isempty',...
strfind(A,'TS 0 ')))
gage5 = [];
gage10 = [];
gage13 = [];
gage19 = [];
TS_sec = [];
idx=[Whichline];
n = length(idx);
for i = 1:n
TimeStp = regexp(A{idx(i)},' ','split');
TS_sec = [TS_sec; TimeStp{4}];
gage5 = [gage5; A{idx(i)+5}];
gage10 = [gage10; A{idx(i)+10}];
gage13 = [gage13; A{idx(i)+13}];
gage19 = [gage19; A{idx(i)+19}];
end
% 1st Option
gtable = table(TS_sec,gage5,gage10,gage13,gage19);
writetable(gtable,'gtable.dat','WriteVariableNames',true);
%2nd option
%write_files('gtables.dat', TS_sec, gage5, gage13, gage19);
end
function write_files(fname, TS_sec, gage5, gage13, gage19)
fid = fopen(fname, 'w');
fprintf('%s %s %s %s\n',[TS_sec gage5 gage13 gage19]');
fprintf(fid,'%s %s %s %s\n',[TS_sec gage5 gage13 gage19]');
fclose(fid);
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Genomics and Next Generation Sequencing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!