# Avoid issues with "ToMatlab" Package?

**URL:** <https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711>\
**Category:** Questions\
**Tags:** engineering, mathematica, external-interfaces, modeling, packages-and-paclets\
**Created:** [December 20, 2017, 10:28pm UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711 "2017-12-20T22:28:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisreyes179](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@chrisreyes179](https://community.wolfram.com/u/chrisreyes179)\
**Post date:** [December 20, 2017, 10:28pm UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711/1 "2017-12-20T22:28:37Z")

</div>

Hello All,

I am having issues converting some of my Mathematica Code to Matlab. I am using mathematica to symbolically solve for the frequency response of a MEMS cantilever beam. I am using the Homotopy Analysis Method. I have generated expressions that I need to import into Matlab to run numerical simulations using Matlab’s FSOLVE. I downloaded and have been using ToMatlab package in the wolfram library. This has worked in part but when i copy the converted Matlab syntax statement and paste it into Matlab it is not in the correct format. The codes below illustrate my problem. I have to delete the "" symbols and eliminate the empty space and reformat the ellipsis because i want them to follow the + signs. Not only do I want them to follow the + signs but I need them to make the next entries following the ellipsis go down a line. In other words i need it to be “…ENTER” Where enter is where i have to manually press the enter key. For the line of code i have attached below it is no problem however i have larger statements consisting of thousands of terms when i go to higher orders for the Homotopy method, therefore it is not reasonable to do this manually every time. Please help.

 ![Matlab_Incorrect_Syntax.JPG](https://global.discourse-cdn.com/wolfram/original/3X/4/7/476a0dde760290c41de44bf1cc291f2394cc88cf.jpeg)

 ![Matlab_Correct_Syntax.JPG](https://global.discourse-cdn.com/wolfram/original/3X/6/d/6d6ddcf30feaf93ffa428ebe3e887f3278e8ef9c.jpeg)

 ![Mathematica.JPG](https://global.discourse-cdn.com/wolfram/original/2X/a/a55528710c267e95463930849f2abc85acf52857.jpeg)

```
ToMatlab[-(1/16) x[
   2] (8 g2 Omega Sin[beta] SuperStar[b] + 
    Cos[beta] (6 b delta g2 - 8 g2 omega^2 + 8 g2 Omega^2 + 
       4 d delta g4 x[2]^2 + d delta g4 Cos[2 beta] x[2]^2))]

```

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [December 20, 2017, 10:58pm UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711/2 "2017-12-20T22:58:29Z")

</div>

Christopher,

I have never used the ToMatlab package you described but I wrote my own and do the same task as you are doing. You need to right-click and do “Copy as-\> Plain Text” (or Edit menu Copy as plain text). Matlab does not like the default copy format and inserts special characters (which messes up your syntax in MATLAB). I do this once in a while (and periodically forget to do the right type of copy and get the same types of errors you are seeing!)

Regards,

Neil

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [December 20, 2017, 11:10pm UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711/3 "2017-12-20T23:10:16Z")

</div>

Christopher,

I would also be careful running that ToMatlab package – Out of curiosity I took a quick look at it and it has at least one bug that I noticed. I use the `ArcTan[]` function and Mathematica uses the convention of `ArcTan[x,y]` while MATLAB uses `atan2(y,x)`. I do not see where the ToMatlab function reverses the arguments of the function. There may be other similar cases of incompatibilities that need to be handled. Make sure you check things if you use any non-simple functions.

This is why I wrote my own so that I can be certain of the processing of the functions that I use.

Regards

Neil

---

<div class="post-metadata">

**Author:** ![chrisreyes179](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@chrisreyes179](https://community.wolfram.com/u/chrisreyes179)\
**Post date:** [December 21, 2017, 3:19am UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711/4 "2017-12-21T03:19:23Z")

</div>

Neil,

Thank You for your response. By “your own” do you mean that you have created your own code for converting Mathematica code to MATLAB Syntax?

-Chris

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [December 21, 2017, 4:58am UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711/5 "2017-12-21T04:58:38Z")

</div>

Chris,

Yes. I made my own Mathematica to Matlab converter. I think the one in the Wolfram Library Archive is overly complicated (not meant as a criticism – it was written nearly 20 years ago and the wolfram language has changed since then).

-Neil

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [December 21, 2017, 6:07am UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711/6 "2017-12-21T06:07:12Z")

</div>

Chris,

Did the copy as plain text and paste work for you?

---

<div class="post-metadata">

**Author:** ![chrisreyes179](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@chrisreyes179](https://community.wolfram.com/u/chrisreyes179)\
**Post date:** [December 21, 2017, 4:24pm UTC](https://community.wolfram.com/t/avoid-issues-with-tomatlab-package/11711/7 "2017-12-21T16:24:51Z")

</div>

Yes sir it worked perfectly. Thank You for your time!
