thingSpeakRead table to uitable | MATLAB | Forum

Avatar

Please consider registering
Guest

Search

— 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
thingSpeakRead table to uitable
Avatar
wasted
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
1
November 11, 2016 - 8:34 am
sp_Permalink sp_Print

Hey guys!

I am facing a problem inserting a table with my data from thingspeak to a matlab uitable in guide.

 

When I press a button, i run the following code to put the data into the uitable (created with guide before):

data = thingSpeakRead(<ChannelID>, 'DateRange',[datetime('Oct 27, 2016'),datetime('Nov 4, 2016')],'OutputFormat','table')

set(handles.uitable1,'Data',data);

 

and this is the result in the command window:

data =

Timestamps                      Fahrer       Kilometerstand      Fahrtgrund
____________________ _________ ______________ ________________

27-Oct-2016 18:15:25           0                   0                   'Initialisieren'
27-Oct-2016 18:17:01      217314240          0                   'Dienstfahrt'
27-Oct-2016 18:17:34           0                  13                  'Fahrtende'
27-Oct-2016 18:18:05      741914369         13                   'Analyse'
27-Oct-2016 18:18:36           0                  20                  'Fahrtende'

Error using matlab.ui.control.Table/set
While setting the 'Data' property of Table:
Data must be a numeric, logical, or cell array

Error in Test_Download>pushbutton1_Callback (line 82)
set(handles.uitable1,'Data',data);

Error in gui_mainfcn (line 95)
feval(varargin{:});

Error in Test_Download (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)Test_Download('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating UIControl Callback

When i don't use the 'OutputFormat','table'-Option in ThingSpeakRead it works, but then the timestamp and the last coloumn with the strings are missing. Which is bad, because they are necessary for my application.

I don't know how to access the datatypes properly to get everything running. Can anybody help me with this?

 

Thanks a lot! 

Avatar
Adarsh_Murthy

Forum Posts: 59
sp_UserOfflineSmall Offline
2
November 15, 2016 - 8:08 am
sp_Permalink sp_Print

Hi, 

UITABLE is currently supported only on MATLAB Desktop and MATLAB Online. It is not supported on ThingSpeak.

An error is generated by your code because UITABLE at present does not support TABLE and DATETIME types in MATLAB. Therefore, when you read data from ThingSpeak with outputFormat set to Table, the returned table isn't supported by UITABLE. To work around this, here is some example code:

 

% Read data from a channel as a table

data = thingSpeakRead(1417, 'DateRange',[datetime('Oct 27, 2016'),datetime('Oct 28, 2016')], 'outputFormat', 'table');

% Create an empty UITABLE
t = uitable;

% Convert the timestamps in the table to string format (from datetime type)
data.Timestamps = datestr(data.Timestamps);

% Convert the table to a MATLAB Cell array
cellData = table2cell(data);

% Assign the data to UITABLE

t.Data = cellData;

Let us know if this doesn't resolve the issue.

 

Thanks!

Avatar
wasted
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
3
November 17, 2016 - 6:49 am
sp_Permalink sp_Print

Hello Adarsh_Murthy,

thank you for your reply. I did the same thing with my table and formated all vectors to cell array data.

Here is some example code for others facing the same problem:

%%%%%%%%%%%%%%

data=thingSpeakRead(channelID, 'DateRange',[datetime(startdatevar),datetime(enddatevar)],'OutputFormat','table')

%T1 was datetime-variable

T1=data{:,1:1};

T1=datestr(T1);

T1=cellstr(T1);

%T2 is Num-variable

T2=data{:,2:2};

T2=num2str(T2);

T2=cellstr(T2);

%T3 is num-variable

T3=data{:,3:3};

T3=num2str(T3);

T3=cellstr(T3);

%T4 is cell-variable

T4=data{:,4:4};

%%%%%%%%%%

Thanks again for your help!

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: jacktheripper125
28 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:

bbruno22

pudderz

Utkya

Poornak26

LindasHed

reddysiva

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee