Pass data between two Matlab?

20 views (last 30 days)
Abolfazl Nejatian
Abolfazl Nejatian on 26 Sep 2020
Answered: Walter Roberson on 26 Sep 2020
Hi
i have two different codes.
first code evaluates something on a big data and then write it on a Mat file.
second is an App designer file that lunch as a WebApp with Matlab Web App Server.
the problem is writing a file from the first code take long around 34Sec and reading that file from WebApp takes around 15Sec.
and i should repeatedly do this process. the problem is when I use the Load function on my WebApp during that 15 Sec all of the functionality of that app was cease. so I'm seeking a way that can pass data between these two separate Matlabs without writing and reading them from local drive.
thanks in advance,
Nejatian
  1 Comment
Mohammad Sami
Mohammad Sami on 26 Sep 2020
Can I check if you must run the two process separately. You can potentially use parpool and submit a processing task to it using parfeval. You can get a callback with the processed data once task is completed. If you have r2020a and later you can use the thread based parpool to potentially further reduce over head of passing data between process.

Sign in to comment.

Answers (2)

Chris
Chris on 26 Sep 2020
You might be able to load the data in the base workspace then pull it into the app, I am not sure apps would halt while something is going on in the base ws.
Something like:
myDataLocally = evalin('base', ['load(myfile);'])

Walter Roberson
Walter Roberson on 26 Sep 2020
  • you can use tcp/ip to send data between distinct processes
  • you can use one MATLAB with two spmd workers, and use labSend and labReceive to transfer data between workers -- however you have the problem that spmd workers do not have access to the display
  • you can use one MATLAB running the app designer code with one parpool or parfeval worker, and use a parallel data queue to send data back from the worker to the client; https://www.mathworks.com/help/parallel-computing/parallel.pool.dataqueue.send.html
  • If you are on Mac or Linux you can look in the File Exchange for the shared array contribution, which uses operating system shared memory support to make data available to multiple processes. In theory the same technique can be used for Windows but if I recall correctly the FEX contribution would need some editing. Also, it is possible that the FEX contribution will not work correctly with releases since MATLAB changed how it stores complex values
  • instead of saving your file to disk, create a "ramdisk" that emulates a file system in memory
  • if you must save to disk, make it an SSD for performance

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!