Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
C++ implementation of interp2 function

Subject: C++ implementation of interp2 function

From: Yossi

Date: 7 Dec, 2009 22:36:01

Message: 1 of 13

Hi,

I'm using a Matlab script that calls the "interp2" function several times (in loops), this makes the run-time extremely longer.

I want to replace this interp2 Matlab function with a C++ version to make my code faster.

What is the easiest way to do so?
Should i compile the "interp2" to cpp and than call it's DLL in my M file (i don't know how to do the compiling) ? or maybe there is a prepared C++ version of this Matlab function that i can use?

Thanks a lot,
Yossi

Subject: C++ implementation of interp2 function

From: Rune Allnor

Date: 7 Dec, 2009 23:22:14

Message: 2 of 13

On 7 Des, 23:36, "Yossi " <yo...@tx.technion.ac.il> wrote:
> Hi,
>
> I'm using a Matlab script that calls the "interp2" function several times (in loops), this makes the run-time extremely longer.
>
> I want to replace this interp2 Matlab function with a C++ version to make my code faster.
>
> What is the easiest way to do so?

If you want 'easy' stick with matlab.

While C++ programs might be significantly faster than
the matlab counterparts, developing them does not come
for free. Programming C++ requires quite a bit more
knowledge and insight into what a computer is and how
it works, than matlab does.

Rune

Subject: C++ implementation of interp2 function

From: Yossi

Date: 8 Dec, 2009 06:40:19

Message: 3 of 13

Rune Allnor <allnor@tele.ntnu.no> wrote in message <e965c3b5-7d02-4795-9bc6-502be0f7e8ee@r40g2000yqn.googlegroups.com>...
> On 7 Des, 23:36, "Yossi " <yo...@tx.technion.ac.il> wrote:
> > Hi,
> >
> > I'm using a Matlab script that calls the "interp2" function several times (in loops), this makes the run-time extremely longer.
> >
> > I want to replace this interp2 Matlab function with a C++ version to make my code faster.
> >
> > What is the easiest way to do so?
>
> If you want 'easy' stick with matlab.
>
> While C++ programs might be significantly faster than
> the matlab counterparts, developing them does not come
> for free. Programming C++ requires quite a bit more
> knowledge and insight into what a computer is and how
> it works, than matlab does.
>
> Rune


I know C++ programming but i don't want to Reinventing the wheel and write spline2 in cpp by myself. I want to use the Matlab compiler to do so or maybe this translation to cpp is already made and i just have to call it's dll from my M file..

I need this interp2 dll realy badly..
Thanks,
Yossi

Subject: C++ implementation of interp2 function

From: Oliver Woodford

Date: 8 Dec, 2009 09:44:02

Message: 4 of 13

"Yossi " wrote:
> Hi,
>
> I'm using a Matlab script that calls the "interp2" function several times (in loops), this makes the run-time extremely longer.
>
> I want to replace this interp2 Matlab function with a C++ version to make my code faster.
>
> What is the easiest way to do so?
> Should i compile the "interp2" to cpp and than call it's DLL in my M file (i don't know how to do the compiling) ? or maybe there is a prepared C++ version of this Matlab function that i can use?
>
> Thanks a lot,
> Yossi

Hi

If your input data is regularly spaced (e.g. an image) then there is a mex version of interp2 (called vgg_interp2) in the toolbox available here:
http://www.robots.ox.ac.uk/~ojw/files/imrender_v2.4.zip
It's especially useful for sampling multi-channel images. It also runs faster if your compiler supports OpenMP (and you have this option enabled).

Oliver

Subject: C++ implementation of interp2 function

From: Rune Allnor

Date: 8 Dec, 2009 10:14:48

Message: 5 of 13

On 8 Des, 07:40, "Yossi " <yo...@tx.technion.ac.il> wrote:
> Rune Allnor <all...@tele.ntnu.no> wrote in message <e965c3b5-7d02-4795-9bc6-502be0f7e...@r40g2000yqn.googlegroups.com>...
> > On 7 Des, 23:36, "Yossi " <yo...@tx.technion.ac.il> wrote:
> > > Hi,
>
> > > I'm using a Matlab script that calls the "interp2" function several times (in loops), this makes the run-time extremely longer.
>
> > > I want to replace this interp2 Matlab function with a C++ version to make my code faster.
>
> > > What is the easiest way to do so?
>
> > If you want 'easy' stick with matlab.
>
> > While C++ programs might be significantly faster than
> > the matlab counterparts, developing them does not come
> > for free. Programming C++ requires quite a bit more
> > knowledge and insight into what a computer is and how
> > it works, than matlab does.
>
> > Rune
>
> I know C++ programming

Not well enough for what you attempt to do:

1) Somebody who knows C++ would not ask for 'easy' methods
2) Somebody who knows C++ would not ask in a matlab forum

Rune

Subject: C++ implementation of interp2 function

From: Yossi

Date: 8 Dec, 2009 10:43:02

Message: 6 of 13

Rune Allnor <allnor@tele.ntnu.no> wrote in message <0f6f6d4d-5a8a-4703-bc88-b34c242e9a5f@j24g2000yqa.googlegroups.com>...
> On 8 Des, 07:40, "Yossi " <yo...@tx.technion.ac.il> wrote:
> > Rune Allnor <all...@tele.ntnu.no> wrote in message <e965c3b5-7d02-4795-9bc6-502be0f7e...@r40g2000yqn.googlegroups.com>...
> > > On 7 Des, 23:36, "Yossi " <yo...@tx.technion.ac.il> wrote:
> > > > Hi,
> >
> > > > I'm using a Matlab script that calls the "interp2" function several times (in loops), this makes the run-time extremely longer.
> >
> > > > I want to replace this interp2 Matlab function with a C++ version to make my code faster.
> >
> > > > What is the easiest way to do so?
> >
> > > If you want 'easy' stick with matlab.
> >
> > > While C++ programs might be significantly faster than
> > > the matlab counterparts, developing them does not come
> > > for free. Programming C++ requires quite a bit more
> > > knowledge and insight into what a computer is and how
> > > it works, than matlab does.
> >
> > > Rune
> >
> > I know C++ programming
>
> Not well enough for what you attempt to do:
>
> 1) Somebody who knows C++ would not ask for 'easy' methods
> 2) Somebody who knows C++ would not ask in a matlab forum
>
> Rune

I'm just asking for easy methos to translate interp2.m to cpp file, i just don't want to waste my time on "manual" translation to c++ (i think Matlab compiler can do it). I'm asking in this forum because the issue is a Matlab function called "interp2" and maybe the Matlab compiler could do the job here...

Thanks,
Yossi

Subject: C++ implementation of interp2 function

From: Yvonne Haesevoets

Date: 9 Dec, 2009 08:18:01

Message: 7 of 13

This is an excellent question actually. If you haven't found the answer yet, this should help you, I'd think:
http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/f7-996707.html
Otherwise the MATLAB Compiler User's Guide...

Subject: C++ implementation of interp2 function

From: Yvonne Haesevoets

Date: 9 Dec, 2009 08:19:02

Message: 8 of 13

This is an excellent question actually. If you haven't found the answer yet, this should help you, I'd think:
http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/f7-996707.html
Otherwise the MATLAB Compiler User's Guide...

Subject: C++ implementation of interp2 function

From: Oliver Woodford

Date: 9 Dec, 2009 09:37:03

Message: 9 of 13

"Yossi " wrote:
> I'm just asking for easy methos to translate interp2.m to cpp file.

Yossi, did you see my earlier comment? The function I mention might do what you're after (the functionality is mostly the same as interp2, with some differences).

Oliver

Subject: C++ implementation of interp2 function

From: John D'Errico

Date: 9 Dec, 2009 11:14:01

Message: 10 of 13

"Yossi " <yosst@tx.technion.ac.il> wrote in message <hflajm$q8s$1@fred.mathworks.com>...

> I'm just asking for easy methos to translate interp2.m to cpp file, i just don't want to waste my time on "manual" translation to c++ (i think Matlab compiler can do it). I'm asking in this forum because the issue is a Matlab function called "interp2" and maybe the Matlab compiler could do the job here...
>

I would be surprised if the matlab compiler would
actually make interp2 run significantly faster.

A HAND coded version might give you a nice speed
gain, but just brute force compilation often does not
gain much.

John

Subject: C++ implementation of interp2 function

From: Yossi

Date: 9 Dec, 2009 13:37:02

Message: 11 of 13

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <hfo0pp$clg$1@fred.mathworks.com>...
> "Yossi " <yosst@tx.technion.ac.il> wrote in message <hflajm$q8s$1@fred.mathworks.com>...
>
> > I'm just asking for easy methos to translate interp2.m to cpp file, i just don't want to waste my time on "manual" translation to c++ (i think Matlab compiler can do it). I'm asking in this forum because the issue is a Matlab function called "interp2" and maybe the Matlab compiler could do the job here...
> >
>
> I would be surprised if the matlab compiler would
> actually make interp2 run significantly faster.
>
> A HAND coded version might give you a nice speed
> gain, but just brute force compilation often does not
> gain much.
>
> John

Thanks John, maybe its not the right place to ask but if you know where i can find in the web a reliable DLL that wraps a C++ implementation of 2D interpolation, i'll be happy to hear

Thanks,
Yossi

Subject: C++ implementation of interp2 function

From: John D'Errico

Date: 9 Dec, 2009 13:47:02

Message: 12 of 13

"Yossi " <yosst@tx.technion.ac.il> wrote in message <hfo95u$23j$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <hfo0pp$clg$1@fred.mathworks.com>...
> > "Yossi " <yosst@tx.technion.ac.il> wrote in message <hflajm$q8s$1@fred.mathworks.com>...
> >
> > > I'm just asking for easy methos to translate interp2.m to cpp file, i just don't want to waste my time on "manual" translation to c++ (i think Matlab compiler can do it). I'm asking in this forum because the issue is a Matlab function called "interp2" and maybe the Matlab compiler could do the job here...
> > >
> >
> > I would be surprised if the matlab compiler would
> > actually make interp2 run significantly faster.
> >
> > A HAND coded version might give you a nice speed
> > gain, but just brute force compilation often does not
> > gain much.
> >
> > John
>
> Thanks John, maybe its not the right place to ask but if you know where i can find in the web a reliable DLL that wraps a C++ implementation of 2D interpolation, i'll be happy to hear
>

Have you looked on netlib.org?

That is the place I'd first look before any other.

John

Subject: C++ implementation of interp2 function

From: Joaquim Luis

Date: 9 Dec, 2009 13:59:03

Message: 13 of 13

"Yossi " <yosst@tx.technion.ac.il> wrote in message <hfo95u$23j$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <hfo0pp$clg$1@fred.mathworks.com>...
> > "Yossi " <yosst@tx.technion.ac.il> wrote in message <hflajm$q8s$1@fred.mathworks.com>...
> >
> > > I'm just asking for easy methos to translate interp2.m to cpp file, i just don't want to waste my time on "manual" translation to c++ (i think Matlab compiler can do it). I'm asking in this forum because the issue is a Matlab function called "interp2" and maybe the Matlab compiler could do the job here...
> > >
> >
> > I would be surprised if the matlab compiler would
> > actually make interp2 run significantly faster.
> >
> > A HAND coded version might give you a nice speed
> > gain, but just brute force compilation often does not
> > gain much.
> >
> > John
>
> Thanks John, maybe its not the right place to ask but if you know where i can find in the web a reliable DLL that wraps a C++ implementation of 2D interpolation, i'll be happy to hear

Mirone has two of such. One is a wrapper to GMT's 'surface' and another to MB-sytem's 'mbgrid'. They both use minimum curvature. I don't know how they compare to interp2 since I just do not use interp2 because of its absurd memory requirements.

J. Luis

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us