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

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)

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

Thanks for your answer.
Now to specify my problem: I'm not using any graphics, the data is displayed in tables and the GUI is mainly there for 'visual apeal' and for user interaction, i.e. what tables should be displayed or to reset the data displayed.
I don't really understand how a callback can help, because the GUI consists of several scripts that create the html files when the part for each particular file is called in the browser.
As for the external data, the background script fetches that from a webserver as needed, so there won't be a callback when it is updated.
A ring buffer sounds promising, but I haven't the slightest idea what that is or how to use/implement it. Can you give me a link to some documentation?
I just had a different thought. The background script pauses for 1 second after each time it fetches and proceses a new set of data. Is it possible to permit the start of other scripts during that period?
Thanks!
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.
Found a different solution but thanks for your help.

Sign in to comment.

Categories

Products

Asked:

on 13 Oct 2015

Commented:

on 20 Oct 2015

Community Treasure Hunt

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

Start Hunting!