Continuous running of code
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have been trying to implement a way to allow my code to run continuously on a MATLAB graph but with no avail. I have used the drawnow function which has helped me run it in real-time but I would like for the code to run like oscilloscope. Is there a function that I am missing?
3 Kommentare
Geoff Hayes
am 24 Mär. 2015
Alex - yes, it is possible to do this. You should be able to modify the below code to suit your needs.
Antworten (2)
Geoff Hayes
am 21 Mär. 2015
Alex - you could try the following which will generate a sine wave and change the last second of data on each iteration of the while loop
figure;
hold on;
set(gca,'Color','k');
set(gca,'YLim',[-2 2]);
% generate five seconds of data with frequency f
fs = 200;
dt = 1/fs;
t = linspace(0,5-dt,5*fs);
f = 2;
a = 1;
y = a*sin(2*pi*t*f);
h = plot(t,y,'Color','g');
while true
% generate a new second of data
tn = linspace(max(t)+dt,max(t)+1,fs);
% randomly change the frequency
if rand>0.6
fn = randi(5,1,1);
else
fn = f;
end
yn = sin(2*pi*tn*fn);
% remove the old data and replace with the new
t = [t(fs+1:end) tn];
y = [y(fs+1:end) yn];
% update the plot
set(h,'XData',t,'YData',y);
pause(1);
end
Note how set is used to update the x and y data of the handle h which corresponds to plot graphics handle. Try the above and see what happens!
0 Kommentare
Shubham Hokarne
am 4 Jun. 2018
Is there any command in matlab to run the program for infinite time and update the data ?
2 Kommentare
Walter Roberson
am 4 Jun. 2018
Bearbeitet: Walter Roberson
am 4 Jun. 2018
No, MATLAB does not have any transfinite operations, but you might be able to find some useful information about implementation of transfinite quantities in MATLAB from https://www.maths.ox.ac.uk/system/files/attachments/PartB2015-16_web_0.pdf
I think you will find it easier to execute indefinitely, updating as you go, instead of waiting until after an infinite time has passed.
Geoff Hayes
am 4 Jun. 2018
Shubham - which program and which data (should be updated)? Please provide some context. And in the future, please don't post a question as an answer to a different question.
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!