writing cellArray to txt file.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
sermet
le 8 Mar 2014
Réponse apportée : Azzi Abdelmalek
le 8 Mar 2014
%for example;
cellArray=
'p1' [400] [500] [600]
'p2' [650.45] [400.78] [390.90]
[ 3] [400.02] [500.05] [600.120]
%I need to write this cellArray into .txt file as it seems above (3x3). This dimensions would change due to the computations therefore I need to perform loop for writing into txt. Which codes I need to perform orderly place columns and rows of this cellArray into txt file?
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 8 Mar 2014
cellArray={'p1' [400] [500] [600]
'p2' [650.45] [400.78] [390.90]
[ 3] [400.02] [500.05] [600.120]}
c=cellfun(@num2str,cellArray,'un',0)
[n,m]=size(c)
filename = 'file.txt';
form=[repmat('%s ',1,m) ' \r\n']
fid = fopen(filename, 'w');
for k=1:n
fprintf(fid, form, c{k,:});
end
fclose(fid);
0 commentaires
Plus de réponses (0)
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!