display table in command window without { }

27 views (last 30 days)
WG
WG on 8 Dec 2021
Commented: Walter Roberson on 9 Dec 2021
I just updated my Matlab to 2020b.
I created a table:
tt = table({1;2;3;4;5},{'A';'B';'C';'D';[]},{9;10;11;12;[]},{'E';'F';'G';'H';[]})
tt = 5×4 table
Var1 Var2 Var3 Var4 _____ ____________ ____________ ____________ {[1]} {'A' } {[ 9]} {'E' } {[2]} {'B' } {[ 10]} {'F' } {[3]} {'C' } {[ 11]} {'G' } {[4]} {'D' } {[ 12]} {'H' } {[5]} {0×0 double} {0×0 double} {0×0 double}
In the previous matlab 2018 and lower, it is shown without { }, just the content of the cell. Is it possible to "display" it as before, without the { }?

Answers (2)

Rik
Rik on 8 Dec 2021
If you really want to, you can. The formattedDisplayText function was introduced in R2021a.
I read about this one in a Community Highlight blog post.
tt = table({1;2;3;4;5},{'A';'B';'C';'D';''},{9;10;11;12;nan},{'E';'F';'G';'H';''});
str=formattedDisplayText(tt);
strrep(strrep(str,'{',' '),'}',' ')
ans =
" Var1 Var2 Var3 Var4 _____ __________ _______ __________ [1] 'A' [ 9] 'E' [2] 'B' [ 10] 'F' [3] 'C' [ 11] 'G' [4] 'D' [ 12] 'H' [5] 0×0 char [NaN] 0×0 char "
  2 Comments
WG
WG on 9 Dec 2021
Reading some documentation and example, this seems good new function. I will try it after get the 2021b.

Sign in to comment.


Walter Roberson
Walter Roberson on 8 Dec 2021
No, it is not.
However, if you only need that for display purposes, then
tt = table({1;2;3;4;5},{'A';'B';'C';'D';''},{9;10;11;12;nan},{'E';'F';'G';'H';''});
TT = varfun(@(V)categorical(string(V)), tt)
TT = 5×4 table
Fun_Var1 Fun_Var2 Fun_Var3 Fun_Var4 ________ ___________ ___________ ___________ 1 A 9 E 2 B 10 F 3 C 11 G 4 D 12 H 5 <undefined> <undefined> <undefined>
Notice I had to change the [] to ' ' or nan
  1 Comment
WG
WG on 9 Dec 2021
Thanks. This workaround seems good.
Small "problem" is I have table with some column number, and some string. So I need to replace all the [] either with '' or NaN depend on the column class (manually). Any suggestion to do it automatically?

Sign in to comment.

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!