3
$\begingroup$

I want to run the Mathematica file with some extension, like '.m'. But, I don't know, how can I run the code. Please, guide me.

$\endgroup$
  • 4
    $\begingroup$ Have a look at Get. $\endgroup$ – Henrik Schumacher Mar 17 at 12:25
  • $\begingroup$ To keep it simple, pass the full path to the file to the Get function. That's all. $\endgroup$ – Szabolcs Mar 18 at 12:12
  • $\begingroup$ what is ''Get''? There is no link. I can't open this. How can I pass the full path to the file? Can you help me Please? I have Mathematica 11.3 in my system. But, not able to run the code in file with extension ''.m''. $\endgroup$ – MMS Mar 18 at 13:26
  • $\begingroup$ Please help me. Actually I don't know about packages. So, I am facing difficulties. $\endgroup$ – MMS Mar 18 at 18:17
  • 1
    $\begingroup$ Actually, corresponding with OP and checking the *.m file, it is clear from the contents of the file that it is not generated by Mathematica, and is not of Wolfram syntax (hence the close vote). Perhaps the *.m file is from Matlab, as I recall its vector syntax being [v1, v2, ...] that complies with said file. $\endgroup$ – István Zachar Apr 5 at 16:38
2
$\begingroup$

If a file has the extension .m, then I assume you are trying to load a package into your notebook. This can be achieved by calling the package (say called PackageName.m) into your own notebook by doing the following:

  1. You can type into your opening like <<PackageName`, which uses the backtick symbol `. It is probably at the left hand side of your keyboard.

  2. Alternatively, this is a shortcut for the MMA function Get, given in the documentation here. The first example has the above notation I was talking about. Then Get["PackageName.m"] would work.

Here is a screenshot so you can see the backtick in action.

Click on this to take you to my image.

$\endgroup$
  • $\begingroup$ Thank you so much for your kind response. Are you talking about this symbol '' ~ ''. I just type "<<PackageName(~)" in the notebook, but it does not work. I also type ''<<~'', it also does not work. Sorry to say, I am facing difficulty to learn from the example. $\endgroup$ – MMS Mar 17 at 14:13
  • $\begingroup$ I have added a screenshot. You are on the right key I think, but instead you have held-down shift instead. It's a tricky key to type, but my screenshot should help you. $\endgroup$ – Brad Mar 17 at 14:17
  • 1
    $\begingroup$ It's tricky but: enclose any code that has backticks in double backticks. I did this for your answer. $\endgroup$ – J. M. will be back soon Mar 17 at 14:23
  • $\begingroup$ @J.M.isslightlypensive that's one of the worst things that to look at - 5 backticks is far too many. Thanks for your help JM. $\endgroup$ – Brad Mar 17 at 14:24
  • 1
    $\begingroup$ Screenshots aren't much use. If you have to, post your screenshot and more importantly, your code as an edit in your original post. $\endgroup$ – Brad Mar 18 at 18:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.