- 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 (최근 30일)
  
       이전 댓글 표시
    
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
채택된 답변
  Cris LaPierre
    
      
 2020년 5월 22일
        
      편집: Cris LaPierre
    
      
 2020년 5월 22일
  
      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개)
  Cris LaPierre
    
      
 2020년 5월 19일
        
      편집: Cris LaPierre
    
      
 2020년 5월 19일
  
      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
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
참고 항목
카테고리
				Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!