character array vs cell array empty cells

3 Ansichten (letzte 30 Tage)
Will Kinsman
Will Kinsman am 15 Okt. 2016
Kommentiert: Will Kinsman am 15 Okt. 2016
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

Akzeptierte Antwort

Marc Jakobi
Marc Jakobi am 15 Okt. 2016
Bearbeitet: Marc Jakobi am 15 Okt. 2016
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 Kommentar
Will Kinsman
Will Kinsman am 15 Okt. 2016
Thanks Marc! For some reason forgot about cell2table, as i dont use tables that often.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by