How to run GUI in Matlab browser and script at the same time

2 views (last 30 days)
I'm building a demonstrator for a project of mine. I have the background script working fine and the GUI also works by itself.
The problem I have is that the script needs to work constantly in the background to process data as it comes in, and the GUI should display the data in realtime. I build the GUI with html, so I have a few scripts for the GUI that write the data into the html files as needed.
The problem I found today is that I cannot execute the background script and the GUI at the same time in the client. I have been using global variables to shift data between various subscripts and the GUI scripts, which won't work if I run one or the other on a worker.
My question has two parts: One, is it possible to run both scripts on the client, i.e. that the GUI can interrupt the background script for short periods (that is acceptable)?
Two, if that is not possible, how do I make the data accessible for the GUI? I thought about using files and such but the problem there is, what happens if the GUI script tries to read a file while the background script tries to write?
Thanks for the help.

Answers (1)

Walter Roberson
Walter Roberson on 13 Oct 2015
Write the background script as a callback for data being received by whatever kind of input you are using (just about everything except audiorecorder() has data ready callbacks.) The graphics runs off callbacks too. For automatic updates of the graphics you can call them from the data callback or you can call them from a timer.
I don't have a link to the FAQ about sharing variables handy on my phone.
You might want to use a ring buffer
  3 Comments
Walter Roberson
Walter Roberson on 19 Oct 2015
Do not have the background script loop. Have it fetch only once and then return. And start a timer that invokes the script.
I am not clear on when the graphics needs to be updated. You started by saying it had to be updated in real time but now you say it is there for visual appeal.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!