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 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