run two scripts with timer
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I have two scripts that I want to execute in parallel. I can't send each script to different threads, because workers don't support plots nor send info between them.
I think we can update the plot from a worker using queued data, but I have no idea how. Also, timer is supposed to do this, I set it up like this:
%main script
f=figure('units','Normalized','Outerposition',[0 0 1 1]);
grid('on');
axis('auto')
h=animatedline('color','b','marker','.');
%% variables
i=1;
i_max=600;
x=[];
means=[];
count=0;
count_max=100;
espera=count_max/20;
i_max=600;
running=true;
t = timer('TimerFcn', 'script1;','StartDelay',1,'ExecutionMode','singleShot');
tt = timer('TimerFcn', 'script2;','StartDelay',1,'ExecutionMode','singleShot');
start(t);
start(tt);
disp('done')
However, this only runs t first and then tt. The output is:
>> main
done
start script1
end script1
start script2
end script2'
The scripts are:
%script1
disp('start script1')
while i<=i_max
x=[x;sin(i)+rand*randi([1 5])];
for k=1:lh
addpoints(h_notsave(k),i,x(i));
end
drawnow
i=i+1;
count=count+1;
end
running=false;
disp('')
disp('end script1')
%script2
disp('start script2')
while running
if count>=count_max
data=x(end-count_max+1:end);
means=[means;mean(data)];
count=0;
disp('inside if')
end
pause(espera);
end
disp('end script2')
5 Commenti
Jan
il 11 Gen 2019
@kira: I cannot read your screen or your mind. Currently I see the code, which contains commands for debugging. I cannot know, how the real code looks like. Please post it.
As far as I understand, the actual problem is not to run 2 scripts in parallel, but to accelerate some code to get a sample rate of 100/s again. I'm convinced, that this is easier to solve than with mutli-threading. E.g. you do not need an screen update with a frequency of 100Hz, because you cannot see it at all on a screen running at 60Hz.
Maybe a multithreading is useful, but in a completely different way.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Entering Commands in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!