How fprintf cell array and martix?
Show older comments
I want to fprintf a cell array and a matrix to a txt file. I used the following code, but got the wrong result.
xx={'2017032312_8953';'2017032312_8978'};
yy=[10;11];
fprintf('%s %e \n ',xx{:}, yy)
The results is:
2017032312_8953 5.000000e+01
017032312_8978 1.000000e+01
I want the result like this:
2017032312_8953 1.0E+01
2017032312_8978 1.1e+01
How can this problem be solved? Many thanks!
Accepted Answer
More Answers (1)
Avoiding the for loop is quite easy too:
C = xx.';
C(2,:) = num2cell(yy);
fprintf('%s %3.1E \n', C{:})
which prints:
2017032312_8953 1.0E+01
2017032312_8978 1.1E+01
2 Comments
Qingsheng Bai
on 5 Sep 2017
Stephen23
on 5 Sep 2017
@Qingsheng Bai: I hope that it helps. You can also vote for my answer if it was useful for you.
Categories
Find more on Matrix Indexing 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!