how can I use dlmwrite for string and matrix in single line ?
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to write a txt file and when I use dlmwrite to write string and matrix together , output file include string in line1 and matrix in line 2 , how can I write them in single line ?
values='values.txt' %output file name
str='set ' %string
col=[1.2,2.2,3.2,4.2,5.2] %matrix
dlmwrite(values,str,'delimiter', '')
dlmwrite(values, col, '-append','delimiter', ' ')
output file is :
set
1.2 2.2 3.2 4.2 5.2
while I want to write :
set 1.2 2.2 3.2 4.2 5.2
Thanks , Farhad
0 commentaires
Réponses (2)
Jang Bahadur Singh
le 8 Déc 2017
Modifié(e) : Walter Roberson
le 8 Déc 2017
str={'set '};
col=[1.2,2.2,3.2,4.2,5.2];
A1 =[a1 col];
er1=table(A1);
writetable(er1,'xx1.txt','Delimiter','\t','WriteRowName',true)
2 commentaires
Georgios Kokogiannakis
le 20 Sep 2018
Hi,
I have the same question as above. writetable is extremely slow for a relatively big dataset.My task is to replace my current code which uses writetable with dlmwrite but I struggle as above (it will save me about 6 hours every time I run the code). I use fprintf for my headers of my csv file fprintf does not put the comma delimiter. Help please.
Walter Roberson
le 20 Sep 2018
data = round( 10 * rand(100,3), 1 ); %for example
headers = {'name1', 'another name', 'var3'}; %for example
ncol = size(data, 2);
fid = fopen('xx1.txt', 'wt');
fprintf(fid, '%s,', headers{1:end-1});
fprintf(fid, '%s\n', headers{end});
fmt = [repmat('%f,', 1, ncol-1), '%f\n'];
fprintf(fid, fmt, data.' ); %transpose is important
fclose(fid);
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!