writing cellArray to txt file.
1 view (last 30 days)
Show older comments
%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 Comments
Accepted Answer
Azzi Abdelmalek
on 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 Comments
More Answers (0)
See Also
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!