display table in command window without { }

27 ビュー (過去 30 日間)
WG
WG 2021 年 12 月 8 日
コメント済み: Walter Roberson 2021 年 12 月 9 日
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 月 9 日
Good point, Rik.

サインインしてコメントする。


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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by