Automatically Run a Matlab Script

I have a script that I want to run automatically, every 5 seconds. How could I set this up so that it runs in an unattended manner?

Respuestas (1)

the cyclist
the cyclist el 3 de Mzo. de 2020

0 votos

9 comentarios

fahd Belmajdoub
fahd Belmajdoub el 3 de Mzo. de 2020
Thank you for your response. Actually, I couldn't find how to schedule a windows task according to the link : http://support.microsoft.com/kb/308569/en-us.
Otherwise, isn't there a script on Matlab to run in an iterative way?
the cyclist
the cyclist el 3 de Mzo. de 2020
Oh, sorry. I should have clicked through to link they suggested. But I think what you want in Windows is the Task Scheduler.
To my knowledge, there is no task-scheduling ability that is fully internal to MATLAB.
fahd Belmajdoub
fahd Belmajdoub el 3 de Mzo. de 2020
Unfortunatly, the task trigger can't be less than one daily. I think we can't adopt the task scheduling for a 5 seconds script sequence.
I actually receive input data from sensors online, then I make some treatment in Matlab before sending the output signal via an OPC client/sever solution. The solution exists in the litterature, but I'm stuck with a static script that doesn't update its data from the online sensors. That's why I need an automatic script runner with 5 seconds interval.
Steven Lord
Steven Lord el 3 de Mzo. de 2020
I'm not completely certain since I haven't used it myself, but if you're not already aware there is an OPC Toolbox that may be of use to you. The "Data Access" section may describe functions and functionality that would be useful to you.
fahd Belmajdoub
fahd Belmajdoub el 5 de Mzo. de 2020
Thank you for you assistance and support. You were right about the OPC Toolbox. I also found this interesting link that tlaks about the same issue: https://www.mathworks.com/matlabcentral/answers/367504-automatically-run-a-matlab-script; I still don't figure it out but we're in the right way for the answer.
the cyclist
the cyclist el 5 de Mzo. de 2020
The page I linked has a section entitled "How to create an advanced task ...".
It looks to me that #21 in that section describes how to repeat the task at higher frequency. (The internet suggested the same to me.)
I don't know if you can go down all the way to 5 seconds, though.
fahd Belmajdoub
fahd Belmajdoub el 5 de Mzo. de 2020
I can repeate the task every 5 minutes, but I can't find less than a minute (see attached figure, for at least 5 minutes frequency)
Steven Lord
Steven Lord el 5 de Mzo. de 2020
Do you need to run the script from the beginning every five seconds, or would running a script that loops indefinitely and polls for data to process every five seconds be sufficient?
fahd Belmajdoub
fahd Belmajdoub el 5 de Mzo. de 2020
Editada: fahd Belmajdoub el 5 de Mzo. de 2020
The script actually consists on importing variables from an OPC server coming from a PLC, make a prediction for a new variable using neural networks, then write this new predicted variable to the OPC server (see code below). So, I think the script should be running systematically in order to retrieve new data from the input variables, and write the new predicted value of the output to OPC server.
%% OPC connection
da= opcda('Localhost', 'Matrikon.OPC.SiemensPLC.1');
connect(da);
%create Group
grp = addgroup(da, 'YYY');
%Add Tags
additem(grp, {'TCP CHANNEL>YYY>FeedRate', 'TCP CHANNEL>YYY>Reject', 'TCP CHANNEL>YYY>puissanceelevderecirc', 'TCP CHANNEL>YYY>Clinker','TCP CHANNEL>YYY>Limestone', 'TCP CHANNEL>YYY>RegistreRecirculation' , 'TCP CHANNEL>YYY>Maindrivepower', 'TCP CHANNEL>YYY>Temperaturesortiebroy', 'TCP CHANNEL>YYY>Puissanceseparateur', 'TCP CHANNEL>YYY>pressionsortiebroyeur', 'TCP CHANNEL>YYY>Electronicear', 'TCP CHANNEL>YYY>Gypsum'});
%Retrieve Data
r = read(grp);
%r(:,1).Value
X = extractfield(r,'Value').';
%Clean up
disconnect(da)
delete(da)
%% Predict output
Y = MatlabMatrixonlyfunction(X)
%% OPC Write
da = opcda('Localhost', 'Matrikon.OPC.SiemensPLC.1');
connect(da);
grp = addgroup(da, 'DemoGroup');
itmIDs = {'TCP CHANNEL>YYY>FinesseLaboratoire'};
itm = additem(grp, itmIDs);
% read and write values to and from the items
write(itm, Y);
R45predite = read(itm);

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Etiquetas

Preguntada:

el 3 de Mzo. de 2020

Editada:

el 5 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by