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

40 vues (au cours des 30 derniers jours)
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 commentaires
Guillaume
Guillaume le 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?
Sean Nykaza
Sean Nykaza le 6 Jan 2020
Thanks for the response, I have now attached the data as requested (in temp.mat).

Connectez-vous pour commenter.

Réponses (1)

Guillaume
Guillaume le 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

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by