display table in command window without { }

27 次查看(过去 30 天)
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 { }?

回答(2 个)

Rik
Rik 2021-12-8
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 个评论
WG
WG 2021-12-9
Reading some documentation and example, this seems good new function. I will try it after get the 2021b.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2021-12-8
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 个评论
WG
WG 2021-12-9
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by