display table in command window without { }

7 vues (au cours des 30 derniers jours)
WG
WG le 8 Déc 2021
Commenté : Walter Roberson le 9 Déc 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 { }?

Réponses (2)

Rik
Rik le 8 Déc 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 commentaires
WG
WG le 9 Déc 2021
Reading some documentation and example, this seems good new function. I will try it after get the 2021b.
Walter Roberson
Walter Roberson le 9 Déc 2021
Good point, Rik.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 8 Déc 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 commentaire
WG
WG le 9 Déc 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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by