Read and send data every second and plot against time
조회 수: 15 (최근 30일)
이전 댓글 표시
Hi,
I got a simple task but I just can't figure out how to solve it. I got a program that reads data from an instrument every 10 seconds. Furthmore it sends out data every second to another instrument. This read in routine is embedded in a while loop and the send out routine is in a run loop. Too keep it simple I'd like to plot the data that is send out over time.
As an example: I want Matlab to open a figure where it starts plotting the data with time on the x-axis. What I need for that would be some sort of continuously running counter. I tried datetick but it doesn't really work. It only shows 00 everywhere.
Not sure if I can simplify the code enough for you to understand but here is the important part:
while x == 1
t1 = timer('TimerFcn',' ','StartDelay',10); %wait 10sec until next measurement
t2 = timer('TimerFcn',' ','StartDelay',1);
start(t1)
wait(t1)
%here would come some code for reading the data
%not important right now
for i=1:10
%some code for sending out data: data_out
plot(data_out)
start(t2)
wait(t2)
end
end
When I now plot that data_out it only works for the duration of the run loop (in this case for 1 - 10 seconds). Then 10 seconds later the run loop is executed again and the plot starts again with x=1 instead of x=11.
I bet there is an easy way to do this but as I said nothing I tried so far worked.
I appreciate every help. Thanks a lot.
댓글 수: 0
답변 (2개)
Walter Roberson
2011년 11월 29일
Before the loop:
xoffset = 0;
In the loop:
numout = length(data_out);
plot(xoffset+(1:numout), data_out);
xoffset = xoffset + numout;
댓글 수: 2
Balu
2015년 2월 1일
s1 = serial('COM4','BaudRate',9600,'DataBits',8);
data=[]; x=0; tic while toc<20
fopen(s1) a=fread(s1,100) fclose(s1);
data=[data;a]; if(length(data)<501) plot(data); else x=x+100; plot(data(0+x:500+x)) % x=x+100; end pause(0.5); % hold on;
end fclose(s1);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!