0

PROBLEM

I have two tools written in MATLAB (I am not the author):

  1. the first allows me to retrieve some data from a SQL database, but it works only on MATLAB 64bit (I have MATLAB 2016b 64bit).
  2. the second uses the data retrieved from the first tool and, through a DLL compiled on a 32bit system, it gets some outputs. As said, this tool works only MATLAB 32bit (I have MATLAB 2013a 32bit).

What I would like to do is:

  1. get the data from SQL, in MATLAB 64bit
  2. "send them" in some way to MATLAB 32bit
  3. run the tool on MATLAB 32bit
  4. "return" the outputs from MATLAB 32bit to MATLAB 64bit

I know a solution may be found using IPC mechanisms, but I am not sure how to find them or how to use them in MATLAB. Does anyone ever worked with this kind of stuff?

Looking into the MATLAB documentation I saw that it is possible to create a COM object, but I am not sure how to use it to run some functions in MATLAB 32bit.

SOLUTION

As suggested by @nekomatic below, everything works for me if I run the code in the way suggested, but excluding -automatic from the system command below. The final system command is in the form

system('"C:\path\to\R2013a\matlab.exe" -wait -r "mycommand; exit"') 

mycommand is a MATLAB script which loads the input file, it does something and then it saves an output file.

2
  • Is speed an issue here? As in, can you afford to wait for MATLAB R2013a to start up each time you need to run the second tool, or do you need the process to complete in seconds or less? Commented Jul 12, 2019 at 9:14
  • No problem with speed. I just want to use mainly MATLAB 64bit to process the data. So, I would need to start a MATLAB 32bit session from MATLAB 64bit, execute a function in MATLAB 32bit, return the outputs to MATLAB 64bit. Commented Jul 12, 2019 at 10:50

1 Answer 1

1

If you don't need this operation to be fast, the easiest way to do it is probably:

  • Save the data from 64-bit MATLAB as a .mat file
  • Use the system command to start an instance of 32-bit MATLAB
  • Run a script in 32-bit MATLAB that reads the data from the file, processes it and saves it
  • Read the result back in to your 64-bit program.

For example the 64-bit code (excluding error handling, current folder setup, etc) might look something like this:

delete result.mat % Delete any result from the previous run save(data.mat, '-v7.3') % usually best to specify the .mat format to use system('"C:\path\to\R2013a\matlab.exe" -automation -wait -r "mycommand; exit"') processedData = load('result.mat') 

where mycommand is your MATLAB R2013a script that reads the data from data.mat, processes it, and saves the result in result.mat.

More data on the startup options for R2013a here (assuming Windows) and on the system command for R2016b here. You may need to be signed in with a Mathworks account to see documentation for older releases, but if that's a problem just look in the help in your respective MATLAB installations.

Sign up to request clarification or add additional context in comments.

5 Comments

If I have a function I want to run in the script testRunScript and function is in the form function output = runScript(input) ... output = function2(input) end, how do I implement it in the code you wrote above? Thanks
Sorry, I don't quite understand the question. In my example you would need to write a script and save it as mycommand.m somewhere on MATLAB R2013a's path, so that you could run it just by typing mycommand in the R2013a command window. That script has to load data.mat from wherever you choose to save it, process it using your DLL, and save the result as result.mat so that the R2016b code can read it in again. I'm assuming that you know the basics of scripts and functions in MATLAB.
Perfect. Sorry, I missed only what you meant for "command" and which structure it should have the "command file". I wrote a simple script which load the mat file, it does some other stuff and then it saves the results in another mat file. The system command in MATLAB 64bit is system('"C:\Program Files (x86)\MATLAB\R2013a\bin\matlab.exe" -automation -wait -r "testRunModel; exit"') but it does not seem to work. I see the cursor loading and nothing happens in the command window (I asked to display some text). testRunModel is the simple .m script.
Does it work if you issue this command from a command prompt? For debugging you could try removing the -automation option, and the ; exit from the string after -r, and you could try the -logfile filename option to capture any output. I don't have R2013a so I can't test this on that specific version, but that's how it should work according to the docs.
That's great @nekomatic! Removing -automatic everything works smoothly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.