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

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

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?
Thanks for the response, I have now attached the data as requested (in temp.mat).

댓글을 달려면 로그인하십시오.

답변 (1개)

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

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 1월 6일

답변:

2020년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by