Printing answers in a word doc
19 views (last 30 days)
Show older comments
Fabiano Da Mota
on 18 Oct 2015
Answered: Steven Lord
on 18 Oct 2015
Hello community,
I am trying to write a code that prints the solutions of system of nonlinear equations into a word doc. I wrote a code that successfully solves for the variables but I am having trouble printing these values into a word doc.
I created the following code:
function F = SL10B(x)
Lab = .1;
Lbc = .6;
Lcd = .3;
Lad = .4;
rabx = Lab*cosd(0);
raby = Lab*sind(0);
F = [ (x(1))^2 + (x(2)^2)- Lbc^2;
(x(3))^2 + (x(4))^2 - Lcd^2;
raby + x(2) + x(4);
rabx + x(1) + x(3) - Lad];
fid = fopen('Solutions.doc','w');
fprintf(fid,'iteration x1 x2 x3 x4 \n');
fprintf(fid,'_______________________________________________________\n')
tab=[x(1);x(2);x(3);x(4)];
fprintf(fid,'%5d %9.2f %8.3f %8.3f %12.4f\n', tab);
end
A word doc opens but nothing is printed on it. How could I fix this?
Thank you.
0 Comments
Accepted Answer
Geoff Hayes
on 18 Oct 2015
Fabiano - while you have given the extension of doc to your file, it won't be a Word document that you are creating but just at text file. Is this sufficient?
As for the reason as to why the file is empty, it is most likely because you haven't closed the file that is identified by fid. Use fclose to close the file once you have finished writing all text to the file as
fclose(fid);
2 Comments
Geoff Hayes
on 18 Oct 2015
Fabiano - x appears to be an input to your function SL10B so it isn't clear to me why you trying to solve for x. This also seems like homework assignment...
Please post this as a separate question, describe what you are trying to do, and include the errors that you observe.
More Answers (1)
Steven Lord
on 18 Oct 2015
Consider one of these options:
- Using PUBLISH to publish your script to a Microsoft Word document.
- Using the Notebook interface.
- Controlling Microsoft Word via its COM interface and invoke the appropriate methods to write to the document.
0 Comments
See Also
Categories
Find more on Manage Products in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!