What is wrong with this ax.Xlim code?

11 次查看(过去 30 天)
Jerry Abdul
Jerry Abdul 2017-3-14
评论: Adam 2017-3-14
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
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
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 CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by