MATLAB: which language interface to use when calling external library functions offered with various interfaces?
Question: Still very new to MATLAB and to programming in general, I got stuck in
understanding how to best make profit from what is documented in the official
MATLAB documentation in the chapter Calling External Functions. I am by now
not capable to judge which of the many offered pathways might be the most
effective one to go for, in terms of how easy a pathway can be learned by a
beginner and which one could on the long term most easy and clear in the
MATLAB code be applied over and over again.

To put it in a very practical question: as, for instance, the third party
image processing function libraries ITK or OpenCV provide Java, C++, C and
Python interfaces, and MATLAB has functionality to address such interfaces,
which interface should a beginner in programming chose? Is one of them usable
in a clearer laid out design and thus easier to get warm with and quicker to
learn to apply?

I am afraid to now hear from everybody something like "well, it depends what
you want to do", and my answer could only be "don´t know yet, I am learning
programming and prefer to first gain some general success by going for the
cleaner designed and easier to understand approach, and thus would like to get
a recommendation where to start".

Please let me add this to my question and concerns: Highly respected Yair
Altman states on his internet page "undocumentedmatlab.com" in the commercial
for his "Undocumented Secrets of Matlab-Java Programming" book, that the
Matlab programming environment would rely on Java for numerous tasks,
including networking, data-processing algorithms and graphical user-interface
(GUI). I derive from this statement that learning to specially connect MATLAB
to JAVA will have significant advantages, THE MATHWORKS itself seem to have
decided to take advantage of such connection when implementing MATLAB.

But I can also see, that THE MATHWORKS by providing for MATLAB the MEX
functionality seems to lean towards a tight C/C++ incorporation, providing
also MEX besides the other possibilities to call external C functions.

For me as a beginner it is now confusing to uncover which route of
connectivity to external languages could be taken as the "standard" or "first
to be recommended" one. Do any of you experienced programmers would have some
arguments for me which route to first focus on? It is a long journey to learn
programming, and I would not like to waste time on poorly recommended
pathways.


Answer: This question sounds like: "I am still learning how to drive, still not a very
experienced driver. Please give me your tips about how to change a flat tire,
what is the best tire to get a flat tire on, passenger side rear? what are the
best places to get a flat tire, is it the mall or my office parking lot or the
middle of the street."

Let me give you some tips:

  * Changing a tire will not make you a more knowledgeable driver. You will learn very few things from doing it and it is a frustrating experience and it is not worth your time right now. Learn how to drive.

**Explanation:** Making MATLAB call Java/C++/C or whatever other language will
not make you a better MATLAB programmer, and frankly is of secondary
importance. Until the first sentence of your question isn't "I'm still new to
MATLAB and programming in general" you're wasting your time. Like changing a
flat tire, connecting MATLAB to other languages is not something cool, or
interesting, in fact it is the opposite: it is frustrating, error prone and
boring.

  * The day will come when you will have a flat tire. That day the location where you get it and which tire it is will become secondary. You will need to learn how to change it and you will. Trust me you will.

**Explanation:** You don't get to decide in what language the code that solves
the exact problem you have right now is written. The same way you don't get to
decide where you get the flat tire. The day will come when you already know
C++ and need MATLAB to call into some C++ code (either your code or someone
else's). That day you will need to learn how to write a mex file in C++ and
compile it for your platform and invoke your code. Or the day will come when
you need to invoke Java, and then you will learn how to call into Java.

Obsessing over this when you don't know what you need to do and you're clearly
not technically equipped to do it is just a waste of time.

