What is wrong with this ax.Xlim code?
조회 수: 11 (최근 30일)
이전 댓글 표시
So basically, I downloaded a code from this website. Im trying to obtain a live data plot from a LM35 temperature sensor. I keep getting an error saying that my ax.xlim line has an error. I have not been able to find out what the error was. Please help. TIA
if true
a = arduino;
v = readVoltage(a,'A1');
temp = v*100;
ii = 0;
temp = zeros(1e4,1);
t = zeros(1e4,1);
tic
while toc < 10
ii = ii+1;
v = readVoltage(a,'A1');
temp(ii) = v*100;
t(ii) = toc;
end
temp = temp(1:ii);
t = t(1:ii);
figure
plot(t,temp,'-o')
xlabel('Elapsed time (sec)')
ylabel('Temperature (\circC)')
title('Temperature Data')
set(gca,'xlim',[t(1) t(ii)])
figure
h = animatedline;
ax = gca;
ax.YGrid = 'on';
ax.YLim = [25 55];
stop = false;
startTime = datetime('now');
while ~stop
v = readVoltage(a,'A1');
temp = v*100;
tim = datetime('now') - startTime;
addpoints(h,datenum(tim),temp)
* _ax.XLim = datenum([tim - seconds(15) tim]);_*
datetick('x','keeplimits')
drawnow
stop = readDigitalPin(a,'D12');
end
end
댓글 수: 4
Rik
2017년 3월 14일
I am guessing that tim will still exist, which would mean that you ax somehow got deleted. I bet you did not close the figure, so my ideas are done here.
My advice would be to try out the set() just in case and go through your code step by step with the debugger. That should help you spot when variables change to values that they should not be.
Adam
2017년 3월 14일
ax.YGrid = 'on';
ax.YLim = [25 55];
both apparently worked fine so I doubt set syntax will change anything.
You ought to be able to see if the axes has been deleted though. Certainly with a breakpoint in the code.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Arduino Hardware에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!