How to execute a MATLAB script in VBA

369 views Asked by At

I want to run a MATLAB script using VBA. I tried running the following code

Set Matlab = CreateObject("Matlab.Application")
result = Matlab.Execute("path to the script")
MsgBox (result)

But it doesn't return anything in the msgbox, nor was the MATLAB workspace modified. How can I know it ran the script?

1

There are 1 answers

2
Dev-iL On

If you want to know whether the script ran, you can have it create an empty file with a timestamp.

fclose(fopen([pwd, date], 'w')); % This only shows the current date

If you see this file after running the VBA command, it means the script ran.

The reason you don't see changes in the workspace is probably because it opens a new MATLAB instance to run your script in.