Page 1 of 1

Runing a Matlab function within an add-in

Posted: Sun Oct 19, 2014 7:38 am
by Itamar
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?

Re: Runing a Matlab function within an add-in

Posted: Mon Oct 20, 2014 8:34 am
by EViews Gareth
I'm not sure I follow what the problem is.

Re: Runing a Matlab function within an add-in

Posted: Tue Oct 21, 2014 12:33 pm
by Itamar
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...

Re: Runing a Matlab function within an add-in

Posted: Tue Oct 21, 2014 12:52 pm
by EViews Gareth
You could use the @runpath or @addinspath functions to determine the path of the add-ins folder.

Re: Runing a Matlab function within an add-in

Posted: Tue Oct 21, 2014 11:14 pm
by Itamar
Perfect! Thank you so much!