How do I read the last 3 Thinkspeak channel statuses into an array?
조회 수: 5 (최근 30일)
이전 댓글 표시
I am currently running a ThingSpeak Maltlab analysis that reads the latest channel status and acts on it. I am using this code, which works fine:
url='https://api.thingspeak.com/channels/mychan/feeds/last.json?api_key=mykey&status=true';
lastData=webread(url);
status = [lastData.status];
I am trying to figure out how to change this to read the last 3 channel statuses and put them into an array like status(i) where i goes from 1-3? This url returns the 3 statuses I want:
url = https:'//api.thingspeak.com/channels/mychan/status.json?api_key=mykey&results=3'
But I can't figure out how to get them into an array to work with. Does anyone know how to do this? Thanks.
댓글 수: 2
Image Analyst
2025년 5월 9일
편집: Image Analyst
2025년 5월 9일
Does anything in the url change when you "read the last 3 channel"? Like mychan or something? Or do you call the same URL, just in a loop after a time delay? Like
for timePoint = 1 : 3
lastData=webread(url);
status(timePoint) = lastData.status;
pause(2); % Pause 2 seconds.
end
What is the lastData variable? What does this show
lastData
whos lastData
채택된 답변
Christopher Stapels
2025년 5월 9일
편집: Christopher Stapels
2025년 5월 9일
url = 'https://api.thingspeak.com/channels/mychan/status.json?api_key=mykey&results=3';
data = webread(url);
statusArray = {data.feeds.status};
Gives you a cell array of statuses (statusi?) :).
Full Disclosure: I did use a little Gen AI to help me on this one.
댓글 수: 3
Christopher Stapels
2025년 5월 9일
Have you tried the MATLAB AI Chat playground? Its uses MATLAB documentation, so it tends to be a little more focused on the MATLAB language.
추가 답변 (0개)
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
참고 항목
카테고리
Help Center 및 File Exchange에서 Write Data to Channel에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!