What is wrong with this ax.Xlim code?

11 visualizzazioni (ultimi 30 giorni)
Jerry Abdul
Jerry Abdul il 14 Mar 2017
Commentato: Adam il 14 Mar 2017
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 Commenti
Rik
Rik il 14 Mar 2017
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 il 14 Mar 2017
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by