Datetime doesn't work in uitable

5 views (last 30 days)
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 Comment
Douglas Anderson
Douglas Anderson on 14 Oct 2021
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);

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Oct 2021
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.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!