From: Aristeidis on
Hi all,

I am the definition of a beginner with mex files. I ve reached a stage with my imaging algorithm where I just have to mex some cell computations for speed. I have optimised the m-code as much as I could but C/C++ seems now the only option to speed things up.

I followed the mex tutorial by Mathworks, though I have to admit it is not very straightforward so I looked at this one as well -> http://www.engineering.uiowa.edu/~dip/lecture/C++_with_Matlab.pdf

Firstly, can anyone confirm that this is indeed the proper procedure to start mex files?
Secondly, I get an error from my VS2010 -> mexFunction.def : error LNK2001: unresolved external symbol mexFunction, as i follow thie above tutorial. My matlab version is 2007b. I would appreciate any help...

Aris
From: Rune Allnor on
On 3 Jul, 15:12, "Aristeidis " <aris...(a)hotmail.com> wrote:
> Hi all,
>
> I am the definition of a beginner with mex files. I ve reached a stage with my imaging algorithm where I just have to mex some cell computations for speed. I have optimised the m-code as much as I could but C/C++ seems now the only option to speed things up.
>
> I followed the mex tutorial by Mathworks, though I have to admit it is not very straightforward so I looked at this one as well ->http://www.engineering.uiowa.edu/~dip/lecture/C++_with_Matlab.pdf
>
> Firstly, can anyone confirm that this is indeed the proper procedure to start mex files?
> Secondly, I get an error from my VS2010 -> mexFunction.def : error LNK2001: unresolved external symbol mexFunction, as i follow thie above tutorial. My matlab version is 2007b. I would appreciate any help...
>
> Aris

Trying to use C and C++ without knowing what you do, is
like the sourcerer's apprentice playing with fire in the
gunpowder arsenal.

Stop what you are doing and learn whatever language, be
it C or C++, first. As somebody wrote where some time
ago,

http://groups.google.no/group/comp.soft-sys.matlab/msg/72e63bfc8f1a7860?hl=no

"Re rogue pointers--that is *exactly* what happens. After
one of these crashes Matlab becomes completely unpredictable.
Sometimes I can keep going. Other times (and at other
stages of debugging) it will close immediately, Windows
will give me a (fatal) runtime error, or--my favorite--it
won't return to the command line and won't let me close it,
either, giving me an error message when I try to do so."

Rune
From: Aristeidis on
> Trying to use C and C++ without knowing what you do, is
> like the sourcerer's apprentice playing with fire in the
> gunpowder arsenal.
>
> Stop what you are doing and learn whatever language, be
> it C or C++, first. As somebody wrote where some time
> ago,
>
> http://groups.google.no/group/comp.soft-sys.matlab/msg/72e63bfc8f1a7860?hl=no
>
> "Re rogue pointers--that is *exactly* what happens. After
> one of these crashes Matlab becomes completely unpredictable.
> Sometimes I can keep going. Other times (and at other
> stages of debugging) it will close immediately, Windows
> will give me a (fatal) runtime error, or--my favorite--it
> won't return to the command line and won't let me close it,
> either, giving me an error message when I try to do so."
>
> Rune

Thanks for the reply and advice Rune.

I didn't say I am not familiar with C++ hence why I chose to write a MEX. I would classify my knowledge on C++ as basic. Besides, the cell computations I hope I d be able to write are quite elementary.
However, I never had to write a MEX-file before and the tutorials I have found are rather general and vague.
My personal experiences tell me as well, that you have to start from somewhere and I asked if there is a such good start somewhere around about this problem apart from Mathworks' documentation. My second question revolved around a problem which might as well be incompatibility (something that I was hoping someone would confirm) between VS2010 - MAT2007b. To be honest, I think I may be slightly off-topic but I guess MEX-ing files can be an important part of a Matlab algorithm if speed is what you are after, right? I mean is there any other option if you ve followed Matlab's profiler word for word and used tic -toc to optimise wherever possible?
From: Rune Allnor on
On 3 Jul, 16:14, "Aristeidis " <aris...(a)hotmail.com> wrote:
>  > Trying to use C and C++ without knowing what you do, is
>
>
>
>
>
> > like the sourcerer's apprentice playing with fire in the
> > gunpowder arsenal.
>
> > Stop what you are doing and learn whatever language, be
> > it C or C++, first. As somebody wrote where some time
> > ago,
>
> >http://groups.google.no/group/comp.soft-sys.matlab/msg/72e63bfc8f1a78...
>
> >   "Re rogue pointers--that is *exactly* what happens.  After
> >    one of these crashes Matlab becomes completely unpredictable.
> >    Sometimes I can keep going.  Other times (and at other
> >    stages of debugging) it will close immediately, Windows
> >    will give me a (fatal) runtime error, or--my favorite--it
> >    won't return to the command line and won't let me close it,
> >    either, giving me an error message when I try to do so."
>
> > Rune
>
> Thanks for the reply and advice Rune.
>
> I didn't say I am not familiar with C++ hence why I chose to write a MEX. I would classify my knowledge on C++ as basic. Besides, the cell computations I hope I d be able to write are quite elementary.

If you say so...

> However, I never had to write a MEX-file before and the tutorials I have found are rather general and vague.

There are a number of example files shipped with matlab.
While not exhaustive, they are quite useful as starting points,
*provided* you already know your C or C++.

I suggested to TMW staff to make these files easier to find
than they have been - I have no idea whether this suggestion
has been acted upon.

Rune
From: Jan Simon on
Dear Aristeidis,

http://www.engineering.uiowa.edu/~dip/lecture/C++_with_Matlab.pdf
>
> Firstly, can anyone confirm that this is indeed the proper procedure to start mex files?

There are some nice examples on the FEX, just look for "mex". You do not have to struggle much with the MSVC interface, if you let Matlab start the compilation with the command MEX.

Good luck, Jan