- don't want to compress the date to a single numeric representation (datenum), and
- also don't want to split the date into parts (datevec), creating a column for each one (Y,M,D,h,m,s)
DateTime stamps in uitable from thingSpeakRead() data
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mark Kiehl
el 19 de Mayo de 2020
Comentada: Cris LaPierre
el 23 de Mayo de 2020
I cannot figure out how to add the date/time stamp data in chnX to the uitable without generating an error.
chnId = #######;
apiReadKey = 'thingspeak-api-read-key';
[data, chnX] = thingSpeakRead(chnId, 'Fields',[1, 2, 3, 4, 5, 6], ...
'NumPoints', 5, ...
'ReadKey', apiReadKey);
% Visualize data with a uitable
f = figure();
uit = uitable(f);
uit.Data = data;
uit.ColumnName = {'A0','A1','A2','A3','A4','A5'};
uit.Position = [5 5 450 150]; %[left bottom width height]
uit.ColumnWidth = {65,65,65,65,65,65};
0 comentarios
Respuesta aceptada
Cris LaPierre
el 22 de Mayo de 2020
Editada: Cris LaPierre
el 22 de Mayo de 2020
My apologies for not catching onto that initially. While uifigure is needed to add datetimes, it is not supported in ThingSpeak. You can find a list of the table properties and their accepted inputs here. From that link, you can see that only numeric, logical, or cell arrays can be passed to the Data property of uitables created with the figure function.
Option 1
You could just display the table without trying to put it into a uitable.
chnId = 1044636;
apiReadKey = 'SJS9JQYUSJSJZYW3';
data = thingSpeakRead(chnId, 'Fields',[1, 2, 3, 4, 5, 6], ...
'NumPoints', 5, ...
'ReadKey', apiReadKey);
% Visualize data
varNames = {'A0','A1','A2','A3','A4','A5'};
Tbl = array2timetable(data,'RowTimes',chnX,'VariableNames',varNames)
Option 2
If you really want it in a table, and
the answer is to create a cell array. To do this, you need to turn the dates into a character array (datestr), and then turn the combined data into a cell array. The easiest way I could find to do that was with table2cell, which meant I first had to turn the data into a table (array2table).
I noticed there is a maximum width allowed for a uitable, so I had to adjust the formatting of the timestamp to get all the columns to fit.
Here is what I came up with.
%% Read Data %%
[data, chnX] = thingSpeakRead(1044636, ...
'Field', [1, 2, 3, 4, 5, 6], ...
'NumPoints', 5);
%% Convert chnX + data to a cell array %%
Tbl = array2table(data);
Tbl.timestamp = datestr(chnX,'mm/dd/yy HH:MM');
Tbl = movevars(Tbl,"timestamp","Before",1);
tblData = table2cell(Tbl);
%% Visualize Data with a uitable %%
f = figure;
uit = uitable(f);
% uit.Data = [dates(:,1),dates(:,2:3)*[1;.01],dates(:,4:6)*[60;1;1/60],data];
uit.Data = tblData;
uit.ColumnName = {'Timestamp','A0','A1','A2','A3','A4','A5'};
uit.Position = [5 5 590 150]; %[left bottom width height]
uit.ColumnWidth = {130,65,65,65,65,65,65};
2 comentarios
Cris LaPierre
el 23 de Mayo de 2020
chnX.Format = 'MM/dd/yy hh:mm';
Tbl.timestamp = char(chnX);
Más respuestas (2)
Cris LaPierre
el 19 de Mayo de 2020
Editada: Cris LaPierre
el 19 de Mayo de 2020
Try using uifigure instead of figure. We don't have access to your channel, so here's a quick mockup I did using a public channel. To support multiple data types in the output, I also had to add the "OutputFormat","table" Name-Value pair to thingSpeakRead.
chnId = 841669;
[data, chnX] = thingSpeakRead(chnId,'Fields',[1, 2],...
'NumPoints', 5, ...
"OutputFormat","table");
% Visualize data with a uitable
f = uifigure();
uit = uitable(f);
uit.Data = data;
uit.ColumnName = {'Date','A1','A2'};
uit.Position = [5 5 450 150]; %[left bottom width height]
uit.ColumnWidth = {150,65,65};
4 comentarios
Comunidades de usuarios
Más respuestas en ThingSpeak Community
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!