Feed on
Posts
Comments

manually writing out matlab matrices in latex is really tedious. here’s how to save yourself the time:

assume you have some matrix L

>> s = sym(L);
>> v = vpa(s,5); # assign numerical precision
>> latex(v)

matlab should now spit out the latex source code that you can directly copy into your .tex file.


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

6 Responses to “insert a matlab matrix into latex automatically”

  1. on 24 Jun 2008 at 8:25 am Soumya

    Could you help me in inserting a matrix within a line…all my efforts are producing the matrix in the next line. Thanks in advance.

  2. on 26 Feb 2009 at 6:33 pm rambonit

    Thanks, I didn’t know about this feature. Very useful.

  3. on 19 Apr 2009 at 2:02 pm Matlab2Latex « wAnNaBe NeRd

    [...] http://desk.stinkpot.org:8080/tricks/index.php/2006/03/insert-a-matlab-matrix-into-latex-automatical… [...]

  4. on 23 Nov 2009 at 12:24 pm Matt

    Very helpful, thank you!!

  5. on 26 Sep 2011 at 4:40 pm shun

    Doesn’t work perfectly for me on 2010a.
    The output precision is the same.
    vpa(A,3) : I have 0.333
    but after latex(vpa(A,3))
    I have 0.33333333333333

  6. on 06 Oct 2011 at 6:22 pm Stefano

    Try this:

    digits(4); //this changes the output precision
    s=sym(A,’d'); //the ‘d’ flag makes sure the sym output is in decimal form
    latex(s);

    worked for me!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS