Trying to Set Data in UITable, but getting error: Values within a cell array must be numeric, logical, or char

18 views (last 30 days)
I am trying to set data for a UItable in App designer. Although the table is 201x15 cell array I get the following error message when attempting to set the UItable:
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
All cells in the array contain char arrays (see attached picture for data). I'm at a loss with what I'm doing wrong as I'm relatively new to app designer. Any help is appreciated.

Answers (1)

Guillaume
Guillaume on 6 Jan 2020
The error message is indeed correct. All the elements of rows 2:end of column 1, 6 and 11 of your cell array are themselves 1x1 cell arrays of char vectors. Unfortunately, matlab display these the same as char vectors so it's not obvious when looking at it the variable editor.
It's obvious if you look at the output of
celltypes = cellfun(@class, returnFile, 'UniformOutput', false) %get class of each cell
Ideally, you'd go back to whichever code created the cell array and fix it. If it's not possible:
%This code assumes that all incorrect cells contain a 1x1 cell array of valid content
celltypes = cellfun(@class, returnFile, 'UniformOutput', false) %get class of each cell
toreplace = strcmp(celltypes, 'cell');
returnFile(toreplace) = cellfun(@(c) c{1}, returnFile(toreplace), 'UniformOutput', false);
Or, using an explicit loop (may be faster):
%This code assumes that all incorrect cells contain a 1x1 cell array of valid content
for idx = 1:numel(returnFile)
if iscell(returnFile{idx})
returnFile{idx} = returnFile{idx}{1};
end
end

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!