How do I loop a program that waits for a .dat file to be updated?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sam Soifer
el 19 de Nov. de 2018
Comentada: Luna
el 20 de Nov. de 2018
I am trying to loop a program that calls data from a gui input.
In this case 'steps.dat' is created from a gui input and everytime the input changes so does the .dat file. Now I need to loop this program so that everytime the input changes the program runs, but i dont want it to run endlessly i want it to wait for the .dat file to be changed.
Thank you
while
F=load('steps.dat')
for motornum= 1:3
direc= sign(F(motornum))
steps=abs(F(motornum))
end
end
3 comentarios
Luna
el 20 de Nov. de 2018
Your gui element means when you import your .dat file to your gui by using a browse button, etc.
Define a callback function for that uicontrol object then you can do what ever you want, each time you clicked the button matlab calls the callback function.
Respuesta aceptada
Mark Sherstan
el 19 de Nov. de 2018
Depending on the size of your .dat file this may work for your application:
while
while ~isfile('steps.dat'); end
F = load('steps.dat');
for motornum = 1:3
direc = sign(F(motornum));
steps = abs(F(motornum));
end
delete steps.dat
end
5 comentarios
Mark Sherstan
el 20 de Nov. de 2018
Something from your GUI writing the file isent being initialized then. It worked for me when I dragged the file into the directory.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!