dlmwrite -append problems when writing char and numbers to .txt file
1 回表示 (過去 30 日間)
古いコメントを表示
I am having troubles trying to write a mix of char and numbers to a delimited file.
that dlmwrite cannot handle both char and num and must use a cell array and thus dlmwrite treats each char as a separate element and places a delimiter between each char and number.
basically what i am doing is reading in a large csv files with mix of char and numbers and sorting through the file line by line and only copying the lines that are for the same location (based on a unique id code) to a new file. the data is a mixed bag of temp for all the met stations in tanzania.
example line from my data: "TANZANIA,UNITED REPUBLIC OF",TZ03MSKR,,MUSEKERA,-9.3,33.6,12,1/1/1943,139
once found, i want to copy the exact line to a new file. most importantly i need to append each line to the existing file as my original file is for 35+ years of monthly readings for each 129 different stations.
i got everything working except the append part.
essentially its the same problem as this
filename = 'C:\test.txt';
str = 'test123';
dlmwrite(filename, str, '-append')
returns
t,e,s,t,1,2,3
i was wondering if anyone can help point out a workaround that is different from the quoted thread or is this the best method?
Thanx.
0 件のコメント
採用された回答
Oleg Komarov
2011 年 7 月 22 日
If you have an example input as, use fprintf:
out = {'"TANZANIA,UNITED REPUBLIC OF"','TZ03MSKR','MUSEKERA',-9.3,33.6,12,'1/1/1943',139
'"My Republic"','TZ03MSKR','MUSEKERA',3,3.6,1,'1/21/1941',111};
out = out.';
fid = fopen('test.csv','a');
fprintf(fid,'%s,%s,%s,%f,%f,%f,%s,%f\r\n',out{:});
fid = fclose(fid);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!