Runing a Matlab function within an add-in

For tips, questions and general information about writing Add-ins, how to package them, and how to submit them to EViews for publication.

Moderators: EViews Gareth, EViews Moderator

Itamar
Posts: 25
Joined: Wed Mar 12, 2014 12:31 pm

Runing a Matlab function within an add-in

Postby Itamar » Sun Oct 19, 2014 7:38 am

Hi,

I want to use the COM capabilities that EViews has with Matlab from an add-in. More specifically, I want to install a matlab function m file in the add-in's directory such that I can 'xrun' it when the add-in is in use. My problem is that I can 'xrun' it only if I know where the m file is at (unless the add-ins direcory is in matlab's path) - a problem since the add-in's path varies with each end-user. Any way I can overcome this?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: Runing a Matlab function within an add-in

Postby EViews Gareth » Mon Oct 20, 2014 8:34 am

I'm not sure I follow what the problem is.
Follow us on Twitter @IHSEViews

Itamar
Posts: 25
Joined: Wed Mar 12, 2014 12:31 pm

Re: Runing a Matlab function within an add-in

Postby Itamar » Tue Oct 21, 2014 12:33 pm

Sorry. I'll try to be more specific:

I want to run a Matlab program within an add-in. The Matlab program calls to a Matlab function file. The Matlab function file is located in the Add-in's folder directory.

Now let's say that this is my Matlab function:

function y = f(x)
y=x
end

'f' is saved under 'f.m' in the add-ins directory.

Next, I want to run from EViews something like:

xrun "a=10"
xrun "b = f(a)"

My problem is that the second line will run only if 'f.m' is in Matlab's current directory, which most likely won't be the add-in's directory. Since the add-ins library path depends on the user's name I can't know in advance how to tell Matlab to go there by using the 'cd()' command.

Hope I was clearer...

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: Runing a Matlab function within an add-in

Postby EViews Gareth » Tue Oct 21, 2014 12:52 pm

You could use the @runpath or @addinspath functions to determine the path of the add-ins folder.
Follow us on Twitter @IHSEViews

Itamar
Posts: 25
Joined: Wed Mar 12, 2014 12:31 pm

Re: Runing a Matlab function within an add-in

Postby Itamar » Tue Oct 21, 2014 11:14 pm

Perfect! Thank you so much!


Return to “Add-in Writing area”

Who is online

Users browsing this forum: No registered users and 4 guests