MATLAB Answers

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

3 views (last 30 days)
Sean Nykaza
Sean Nykaza on 6 Jan 2020
Answered: Guillaume on 6 Jan 2020
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.

  2 Comments

Guillaume
Guillaume on 6 Jan 2020
Clearly, at least one cell is not numeric, logical or char. Can you save your cell array as a mat file and attach to your question?

Sign in to comment.

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

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019b