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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by