Can't use data from thingSpeakRead to parse comma delimited values | ThingSpeak Apps | Forum


Please consider registering


— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Can't use data from thingSpeakRead to parse comma delimited values
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
October 28, 2016 - 3:27 pm
sp_Permalink sp_Print


I'm finding the reference for thingSpeak extremely lacking so I have turned here in exasperation.

I am using the thingSpeakRead() function to read the most recent value from Field 1 of my private channel.  The data that this field stores is a string of comma-separated values.

I want to take this list of values, parse them, and write them to their corresponding field on a different private channel I own.

I have the following code:

data = thingSpeakRead(readChannelID,'ReadKey', readAPIKey,'NumPoints', 1, 'Fields', [1]);

dataArray = strsplit(data, ',');


If I try and run this code, I get the following error message in the "Output" box:

Error using strsplit
First input must be either a character vector or a string scalar.

So, obviously the data that thingSpeakRead() returned was not a string (or "character vector" as I guess MATLAB calls it...).

Not sure where to go from here.... is there a way to access this string of values stored in Field 1?Cry


Forum Posts: 59
sp_UserOfflineSmall Offline
October 28, 2016 - 3:46 pm
sp_Permalink sp_Print


thingSpeakRead() by default returns data back as a numeric array. For your case, since the data on the ThingSpeak channel is a string, you should use the 'OutputFormat' names parameter to request for data back as a table:

data = thingSpeakRead(readChannelID,'ReadKey', readAPIKey,'NumPoints', 1, 'Fields', [1], 'OutputFormat', 'table');

You will then need to access the data in the table (data.<columnName>) to apply strsplit() function. Refer to the following link on how to access data in a table:


If this doesn't work, share the values stored in the data table and we might be able to provide additional suggestions.



New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
November 1, 2016 - 2:45 pm
sp_Permalink sp_Print sp_EditHistory

Thanks for the reply!  Clearly I have a lot to learn about MATLAB...

I now have the thingSpeakRead() function returning a table.  It would appear that it thinks the column with the comma-delimited strings in it is a variable of type double

Here is my code:

%% Read Data %%
data = thingSpeakRead(readChannelID,'ReadKey', readAPIKey, 'OutputFormat', 'table');

%% Analyze Data %%
% Add code in this section to analyze data and store the result in the
% analyzedData variable.

disp ----------------;

testVar = data.allData(1);

disp ----------------;


.... and the output:


Timestamps: 1×1 datetime

min 01-Nov-2016 13:56:35
median 01-Nov-2016 13:56:35
max 01-Nov-2016 13:56:35

allData: 1×1 double

min NaN
median NaN
max NaN
NaNs 1


Name Size Bytes Class Attributes

data 1x2 1198 table
metacl 1x1 8 meta.class
readAPIKey 1x16 32 char
readChannelID 1x1 8 double
testVar 1x1 8 double
writeAPIKey 1x16 32 char
writeChannelID 1x1 8 double


Any idea why I am getting a double instead of a string?Yell


Here is the first few rows of the table, with headers:

created_at entry_id field1
30-10-16 13:14 135 1477844100, 11.13,  0.78,  8.73,  2.14, 11.64,  1.27, 14.74,  3.56, 21.95,  5.41,  0.00,  0.00,  5.01,  1.22,  1.08,  0.25,
30-10-16 13:29 136 1477845000, 11.15,  0.84,  9.39,  2.33, 11.66,  1.29, 15.03,  3.69, 22.85,  5.66,  0.00,  0.00,  5.02,  1.23,  1.07,  0.26,

Forum Posts: 59
sp_UserOfflineSmall Offline
November 2, 2016 - 12:33 pm
sp_Permalink sp_Print


Thanks for sharing the additional info. ThingSpeakRead at present doesn't support the case where a numeric vector is stored in a single field. We will consider this in a future update of the ThingSpeakRead function.

In the meanwhile, to access your data in a MATLAB Analysis App, you can use the following lines of code instead:

data = webread('<channelID>/feeds.json?api_key=<read_Key>&results=1')
myData = data.feeds.field1;


The data returned from thingSpeak will be stored in the variable data as a structure. As shown in your previous post, since the value of interest is stored in field1, myData should contain the data of interest.

NOTE: you need to replace <channelID> and <read_Key> with their appropriate values. 

Let me know if this doesn't work for you.

Bethesda, MD
New Member
Forum Posts: 4
sp_UserOfflineSmall Offline
January 18, 2017 - 12:49 pm
sp_Permalink sp_Print

Adarsh_Murthy, what you recommended works perfectly!

Thank you

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
17 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:







Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565


Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee