필터 지우기
필터 지우기

Setting table column width

조회 수: 11 (최근 30일)
AMM
AMM 2020년 6월 20일
댓글: John K. George 2021년 6월 21일
Apologies in advance for the lengthy example below. Suppose I create a two-column table:
>> t=table((1:2)',repmat(1:5,2,1))
t =
2×2 table
Var1 Var2
____ _____________________
1 1 2 3 4 5
2 1 2 3 4 5
At some point, MATLAB renders the second column in a "compact" format. In this case, this is triggered by adding a sixth element to the arrays in the second column:
>> t=table((1:2)',repmat(1:6,2,1))
t =
2×2 table
Var1 Var2
____ ____________
1 [1×6 double]
2 [1×6 double]
The same thing happens with chars, for which the magic threshold seems to be 10 characters; beyond that, the "compact" format appears:
>> t=table((1:2)',repmat('abcdefghij',2,1))
t =
2×2 table
Var1 Var2
____ __________
1 abcdefghij
2 abcdefghij
>> t=table((1:2)',repmat('abcdefghijk',2,1))
t =
2×2 table
Var1 Var2
____ ___________
1 [1×11 char]
2 [1×11 char]
I'm trying to understand if there is a way to set the width threshold for when this happens. Things I've tried that DO NOT work:
  • Setting the header of the second column to an artificially long name:
>> t=table((1:2)',repmat(1:6,2,1),'VariableNames',{'Short','AVeryLongVariableNameThankYouVeryMuch'})
  • Using addprop:
>> t=addprop(t,'ColumnWidth','table');
>> t.Properties.CustomProperties.ColumnWidth=[30 100]
(and using 'variable' instead of 'table' produces the same output.)
  • Setting output numerical output format:
>> format long e
(and similarly with all the other options I tried with that command.)
I've found a number of posts [1][2][3][4] that ask similar questions, but unless I'm misunderstanding those discussions, none apply here. So is there a way to control the maximum width of table columns?

채택된 답변

Walter Roberson
Walter Roberson 2020년 6월 20일
I'm trying to understand if there is a way to set the width threshold for when this happens.
No, there is not. Those limits are hard-coded in near line 33 of @tabular/disp.m
table() objects are not designed as display objects.
  댓글 수: 1
AMM
AMM 2020년 6월 20일
편집: AMM 2020년 6월 20일
Walter, your depth of MATLAB knowledge is truly amazing. I'll just use a bunch of fprintfs. Not as pretty, but it'll work. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

John K. George
John K. George 2021년 6월 18일
>> t=table((1:2)',repmat(1:5,2,1))
Index in position 1 exceeds array bounds (must not exceed 1).
  댓글 수: 4
Walter Roberson
Walter Roberson 2021년 6월 18일
whos table
whos repmat
if one of them shows up as being a variable then clear the variable.
John K. George
John K. George 2021년 6월 21일
Walter, thank you for your timely response(s) by the way. Much appreciated. It's working now! I'm actually trying to accomplish two things.
  1. The "Select_Sensor" column is currently cut-off at the right.
  2. Ideally, I would like the option of three "Categorical" dropdown menus, one for each column.
As it is, only the first column on the left ("Crew1, Crew2,... etc.) has been expanded to include dropdowns. See the attached script.

댓글을 달려면 로그인하십시오.


John K. George
John K. George 2021년 6월 21일
Attached reply. I had already tried typing "clear" by the way.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by