character array vs cell array empty cells

조회 수: 1 (최근 30일)
Will Kinsman
Will Kinsman 2016년 10월 15일
댓글: Will Kinsman 2016년 10월 15일
I have an array, which is identified by iscell() as a cell array but behaves like a character array:
'jan 7' '2' '' '2.5'
I have 2 questions: 1) why is it not displayed in the console as:
['jan 7'] ['2'] [''] ['2.5']
2) how can i change all [''] cells to [] 3) when trying to create a table with this data I am getting the message: You may have intended to create a table with one row from one or more variables that are character strings. Consider using cell arrays of strings rather than character arrays. Alternatively, create a cell array with one row, and convert that to a table using CELL2TABLE.
Is there a way to convert this array to be easily usable for my table?
Appreciate the help, and I realize this is a pretty basic question but help is appreciated
Thanks,
Will

채택된 답변

Marc Jakobi
Marc Jakobi 2016년 10월 15일
편집: Marc Jakobi 2016년 10월 15일
That's 3 questions ;)
  1. I'm not sure I understand what you mean. If I create a cell array, it displays like this in the command window.
C = { 'jan 7' '2' '' '2.5'}
C =
1×4 cell array
'jan 7' '2' '' '2.5'
which is perfectly normal.
2. I would either create an empty copy of C and move the other values over
D = cell(size(C));
tf = ~ismember(C,'');
D(tf) = C(tf); % this will create an array {'jan 7' '2' [] '2.5'}
or alternatively just remove the cells from C:
C(~ismember(C,'')) = []; % this will create an array {'jan 7' '2' '2.5'}
3. Which function are you trying to use to create the table? If I use
T = cell2table(C);
it works just fine.
  댓글 수: 1
Will Kinsman
Will Kinsman 2016년 10월 15일
Thanks Marc! For some reason forgot about cell2table, as i dont use tables that often.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by