MATLAB Answers


Matlab Compiler Magic Numbers example won't work

Asked by Ryan Matheson on 29 Jan 2013
Latest activity Edited by Jintao Chen on 17 Nov 2016

I have followed the magic number example in the documentation and for whatever reason it will not run at all. All it does is make the "windows ding" noise indicating something went wrong but doesn't give me an explanation.

Is there any additional steps to this example I should be making that aren't described in the text?


Log in to comment.

3 Answers

Answer by Titus Edelhofer on 30 Jan 2013

Hi Ryan,

a good way to find out: start a windows command window (hit the windows start button, enter "cmd" as command. It should open the black console window.

cd to the folder where your .exe is.

Start the .exe "manually". Errors get displayed then in the cmd window. That should indicate whats wrong (or give you something that you can post so we have a chance to see what went wrong).



The .m file called magic squares is a pre-made example code that comes with Matlab and can generally be found in


This is a direct example from the resources called "Magic Square Example" which you can find in the help navigator. Essentially my problem is I followed the instructions, which were very simple, and can't figure out what I'm missing. The program should be asking for an input but instead just crashes. I would like to get this example running so I can move on to bigger and more complex things.

Oh wait I see what you mean by the "7" the error read,

Error using magicsquares < 7 >

I am also using your suggestion at this point and did run it in a console.

If you need to pass arguments, you should do so, i.e.,

cd c:\PathToYourExecutable\
magicsquare 5

Where 5 is the parameter n.


Log in to comment.

Answer by Image Analyst
on 29 Jan 2013

Exactly how are you trying to run the exe on the target computer?


Log in to comment.

Answer by Noah Frere on 3 Aug 2016

Hello all. I am having a similar problem, but with MATLAB R2016a. I compiled magicsquares and ran it from terminal in Mac 10.11.4 El Capitan. Here's my command:

 Noahs-MacBook-Pro:application noahfrere$ ./ /Applications/MATLAB/MATLAB_Runtime/v901

and here's the result:

 Setting up environment variables
DYLD_LIBRARY_PATH is .:/Applications/MATLAB/MATLAB_Runtime/v901/runtime/maci64:/Applications/MATLAB/MATLAB_Runtime/v901/bin/maci64:/Applications/MATLAB/MATLAB_Runtime/v901/sys/os/maci64
Not enough input arguments.
Error in magicsquare (line 7) 

I did not enter the argument this time since I followed the prescription that worked for a different function:

 function hello
    disp('hello jill')

which worked just fine, using in Terminal:

 Noahs-MacBook-Pro:for_redistribution_files_only noahfrere$ ./ /Applications/MATLAB/MATLAB_Runtime/v901

which output:

Setting up environment variables
DYLD_LIBRARY_PATH is .:/Applications/MATLAB/MATLAB_Runtime/v901/runtime/maci64:/Applications/MATLAB/MATLAB_Runtime/v901/bin/maci64:/Applications/MATLAB/MATLAB_Runtime/v901/sys/os/maci64
hello jill

When I tried running magic squares as recommended in the Mathworks tutorial:

 Noahs-MacBook-Pro:application noahfrere$ ./ 5

then the result is:

 dyld: Library not loaded: @rpath/libmwlaunchermain.dylib
  Referenced from: /Applications/magicsquare/application/./
  Reason: image not found
Trace/BPT trap: 5

I tried a little coding following the readme.txt, which says: "If it is defined, set it to the concatenation of these strings:


changing the contents of the file so that it included "v901", which it did not include initially. However, I did not do that for the hello jill function. Either way, I couldn't get the magic squares executable to display the magic square.

Any ideas?

Also, the whole point of this is to eventually make a pretty complicated GUIDE gui executable. -or at least the functions that the gui contains. (that is, it doesn't have to be the gui if Matlab doesn't support that kind of activity). Basically, my code takes a bunch of data and takes the fft(data), the stft(data), graphs it, finds total energy, and finds percent error between the un-interpolated and the interpolated computations, and the frequencies at which the maximum values of the energy spectrum occur, for different sets of data. The idea is that when we get new data, we can analyze all of it with a single click on anyone's computer, rather than import it into Matlab, since not everyone will be using Matlab presumably.

Thanks for any help!


  1 Comment

Hi Noah,

Hope you have solved your problem already. First thing first, there is no need to modify the output sh program.

For the issue of:

Not enough input arguments.

My answer may sound stupid, but you may want to check to see if you added below code at the beginning of your code out of practice, which I did.

clc; clear; 

It removes the argument I just input. Remove it if you have it.

For the issue of

Reason: image not found

The command

./ 5

you used doesn't make sense for me because - you first miss the space between used app and reference file - you are referring to only the library related with magicsquare but not other essential library for the standalone executable to run

Try this command instead and it may solve your issue

./ /Applications/MATLAB/MATLAB_Runtime/v901 5'

Hope it helps.

Appreciate you sharing your questions here, it helped me to solve my issue.

Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today