Here is how you can read a specific field from a JSON response in MATLAB using the JSONlab toolbox:
- Install JSONlab toolbox if you don't already have it:
pkg install -forge jsonlab
- Make a GET request to your API endpoint to get the JSON response:
url = 'https://api.thingspeak.com/channels/YOUR_CHANNEL_ID/feeds.json?api_key=YOUR_API_KEY';
json_text = webread(url);
- Parse the JSON text into a MATLAB struct:
json = jsondecode(json_text);
- Access the specific field you want from the struct (field8 in this example):
field8_data = json.feeds(1).field8;
The field8_data variable will now contain the data for field8 from the first entry in the feeds array.
You can loop through all entries to access field8 for each:
for i = 1:length(json.feeds)
field8(i) = json.feeds(i).field8;
end