Datetime doesn't work in uitable

5 次查看(过去 30 天)
Hello,
I input several cell arrays to a uitable that I would like to be able to sort. The other cell arrays are numeric or strings, but if I include the datetime cell array I get the following error:
Error using matlab.ui.control.Table/set
Error setting property 'Data' of class 'Table':
Values within a cell array must be numeric, logical, or char
Error in va2_17>shot_wizard_button_Callback (line 247)
set(handles.file_table,'Data',the_data2);
I suppose I could separate the datetime into date and time, but then couldn't sort, right? Any thoughts?
Thanks.
Doug
  1 个评论
Douglas Anderson
Douglas Anderson 2021-10-14
FYI, here is the code
% Load table
serial_numbers = struc_file.serial_number;
file_names = struc_file.file_name;
date_time = struc_file.event_date_time;
ppv = struc_file.ppv;
% Fix Serial Number format, removing Carriage Return
for n = 1:length(serial_numbers)
sss = serial_numbers{n};
ss2 = sss(1:4);
serial_numbers{n} = ss2;
end
% The following works without date_time
the_data2 = [serial_numbers,file_names,date_time,ppv]; %date_time,ppv];
set(handles.file_table,'Data',the_data2);

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2021-10-14
Your reference to handles.file_table tells us that you are using GUIDE and "traditional figures". And in traditional figures, uitable() does not support datatime values.
If you use an ISO format such as uuuuMMdd HH:mm:ss and string() the result, then what you get can be sorted. But keep in mind that uitable() in traditional figures do not offer sort operations themselves. The ability to click on a header to sort is offered only for uitable within uifigure()... which I believe do support datetime elements.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by