Give title for Table

500 views (last 30 days)
Elysi Cochin
Elysi Cochin on 2 May 2021
Commented: Adam Danz on 21 Jun 2022
Is it possible to give title for a table i have displayed as below
If i wanted to give a title 'My Table', how to give it?
Details = [38,71,176,124,93;...
43,69,163,109,77;...
38,64,131,125,83;...
40,67,133,117,75;...
49,64,119,122,80];
T = array2table(Details,...
'VariableNames',{'Age' 'Height' 'Weight' 'BP_High' 'BP_Low'},...
'RowNames',{'Smith';'Johnson';'Williams';'Jones';'Brown'});
disp(T)

Accepted Answer

Adam Danz
Adam Danz on 3 May 2021
Edited: Adam Danz on 3 May 2021
You could effectively give a title to a table by nesting the table within another single-column table that contains the title.
Details = [38,71,176,124,93;...
43,69,163,109,77;...
38,64,131,125,83;...
40,67,133,117,75;...
49,64,119,122,80];
T = array2table(Details,...
'VariableNames',{'Age' 'Height' 'Weight' 'BP_High' 'BP_Low'},...
'RowNames',{'Smith';'Johnson';'Williams';'Jones';'Brown'});
T = table(T,'VariableNames',{'My Table'}); % Nested table
disp(T)
My Table Age Height Weight BP_High BP_Low ________________________________________________________ Smith 38 71 176 124 93 Johnson 43 69 163 109 77 Williams 38 64 131 125 83 Jones 40 67 133 117 75 Brown 49 64 119 122 80
However, now you'll have to index the table differently. For example, to access Height,
T.('My Table').Height
Or to access the 3rd row,
T.('My Table')(3,:)
or you could un-nest the table,
T = T.('My Table');
  5 Comments
Adam Danz
Adam Danz on 3 May 2021
There isn't much utillity in assigning a table title in Matlab. It requires additional steps when accessing the data and doesn't offer any additional benefits in referencing tables. If the table is to be displayed in a text file, the title could be added within the file after exporting it. If you want to display the title in the command window and identify the table by some kind of table name, you could always use an fprintf command to display the title name just before displaying the table.
Elysi Cochin
Elysi Cochin on 3 May 2021
Yes sir, that is a better and simple option in my case, as i just need to display. Thank you sir

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 3 May 2021
No, table() is designed for programming, not for display purposes.
  3 Comments
Walter Roberson
Walter Roberson on 3 May 2021
Yes, it is possible to give a title to a table.
filename = fullfile(matlabroot, 'toolbox', 'matlab', 'datatypes', 'tabular', '@tabular', 'disp.m');
edit(filename)
Look close to the end of the first function, somewhere near line 265. You will see code that looks like
[varChars,nestedVarChars,underlines] = getVarNamesDispLines();
disp(char(varChars));
That is the line of code that displays the variable names, and the next few lines of code display headers and then the content. By this point in the code, everything has been computed and put into arrays for later display.
So just before that getVarNamesDispLines(), insert your code that figures out the title to use for the table, and then display it.
Last I recall you were using R2017a. If you were using R2018b or later you could use addprop() https://www.mathworks.com/help/matlab/ref/addprop.html to create a custom table property. Custom table properties are not displayed, but they are stored with the table, so you could addprop() a title, and then in the code for tabular disp, check to see if the property exists and if so then display it.
This is all to answer the question of whether it is possible to give a title to a table: the answer is Yes, you can modify the Mathworks-supplied code to allow for a title. If the question where whether there is any supported method, the answer would be what I originally posted: NO.
Elysi Cochin
Elysi Cochin on 3 May 2021
Thank you so much for the detailed explaination

Sign in to comment.


Abdul Kalam.A
Abdul Kalam.A on 18 Jun 2022
if you want to display in command widow
fprintf(' your title')
tabulations = table(your parameters)
  1 Comment
Adam Danz
Adam Danz on 21 Jun 2022
  1. Don't forget to add a newline (\n) after the fprintf string,
fprintf('your title\n')
2. The table that is printed by the table() command may be truncated if it is too wide or too tall. This is why it's better to use disp
Compare the following outputs:
T = table(rand(500,1), char(randi(26,500,3)+64))
T = 500×2 table
Var1 Var2 ________ ____ 0.93061 TDH 0.53786 XUQ 0.59648 ZNJ 0.58464 JIX 0.84478 RBG 0.049309 FTN 0.49092 HCN 0.79889 EZS 0.47739 SZU 0.15345 WSC 0.31641 YTG 0.93983 RFL 0.6301 SNQ 0.062908 RGB 0.83948 UKZ 0.3859 SUV
disp(T)
Var1 Var2 _________ ____ 0.93061 TDH 0.53786 XUQ 0.59648 ZNJ 0.58464 JIX 0.84478 RBG 0.049309 FTN 0.49092 HCN 0.79889 EZS 0.47739 SZU 0.15345 WSC 0.31641 YTG 0.93983 RFL 0.6301 SNQ 0.062908 RGB 0.83948 UKZ 0.3859 SUV 0.15473 AAC 0.60835 XES 0.73843 LPN 0.59334 ERY 0.20842 DPG 0.71571 ADX 0.58434 RFN 0.82014 MXO 0.72198 UFV 0.55202 HUO 0.20095 ZIS 0.74301 SET 0.71594 COF 0.29006 EBK 0.69775 MJK 0.039908 NPA 0.4789 ZYV 0.53072 ZVT 0.44424 IQO 0.29553 LFI 0.48903 XGO 0.096159 BEO 0.0072741 BWW 0.86065 RWQ 0.46507 YXB 0.023041 XRL 0.29677 QDB 0.44214 KNE 0.97059 JSB 0.84123 NWY 0.30471 CJO 0.96345 XMH 0.66706 YJJ 0.75639 KXI 0.2064 FYZ 0.26268 UAS 0.48056 EDJ 0.56402 MGV 0.13583 XBA 0.36014 WYA 0.62381 TNZ 0.42686 KID 0.71987 LBO 0.49834 PPE 0.90097 SYT 0.85856 WBZ 0.44405 CLJ 0.45846 RHC 0.67214 AGR 0.0050021 HLF 0.16589 CNG 0.97173 ZOH 0.054269 NUJ 0.68344 BDN 0.7463 YRO 0.31903 TIS 0.0099346 MBU 0.45217 GSL 0.79534 RYO 0.29004 GQE 0.68207 UZE 0.39677 TSB 0.74801 NIX 0.40383 OUG 0.63623 RAT 0.96529 ATK 0.23684 XHN 0.70086 IYO 0.14566 LDJ 0.057449 EDT 0.81261 ONC 0.060188 PMX 0.8937 NME 0.76409 QTK 0.29291 DIN 0.20677 KWX 0.53763 KOR 0.55434 EXA 0.86944 EQH 0.25204 OQP 0.45192 EAG 0.62594 BSC 0.93447 UVT 0.98932 WYM 0.86968 SVM 0.2708 OEC 0.98835 PNX 0.87166 BPA 0.31059 TUF 0.50077 JVS 0.051601 NIB 0.80893 QSV 0.36254 CZV 0.18495 TQN 0.56708 LPA 0.95789 OAL 0.5567 HTL 0.82296 QHK 0.6567 VVS 0.44095 PWG 0.098273 HDA 0.26811 YTH 0.25761 KBF 0.92096 IVU 0.28123 AQN 0.58084 SXU 0.64789 AUL 0.1864 IBQ 0.84202 TUW 0.064151 WEJ 0.38442 TOS 0.45922 ZTZ 0.42471 USF 0.83278 QDI 0.42609 PBM 0.75958 MPQ 0.27578 SWV 0.56177 VZC 0.51507 FRH 0.12709 TVO 0.40035 WPT 0.67101 JJI 0.89849 HDZ 0.4467 WJO 0.57601 ADW 0.70756 ZUF 0.32143 QUS 0.60643 VOT 0.52699 ENG 0.22481 JCR 0.57336 RQA 0.33149 DXI 0.057317 XHC 0.82115 LBC 0.83043 NDW 0.56164 CFO 0.8839 FKD 0.44184 JNM 0.5545 IPX 0.9872 PCF 0.075449 QLX 0.69973 VAS 0.65499 UYU 0.5003 XKN 0.38949 NNG 0.50527 UAD 0.60557 NFJ 0.71054 ENS 0.95535 GLU 0.68707 TCX 0.30983 EKP 0.56149 ROT 0.58132 BDA 0.09247 LZT 0.37579 NCS 0.48718 TLO 0.29493 PFJ 0.48402 UBK 0.76893 WHW 0.66055 POI 0.41434 BXD 0.1934 LKF 0.43289 SKY 0.055644 FCN 0.77043 UZY 0.02143 EHY 0.36645 HPR 0.0089252 UPC 0.32672 VLH 0.2679 KLH 0.52622 TSP 0.018583 QXQ 0.14745 QQX 0.0045122 FLE 0.63583 GDR 0.29569 QYY 0.67705 JDF 0.018169 RSQ 0.1283 HFN 0.86396 FES 0.4539 EQU 0.13976 LYU 0.45148 LTI 0.47403 LNO 0.019806 BFC 0.24616 RLH 0.71828 BKZ 0.16692 YEH 0.59039 JJQ 0.5644 NIT 0.67756 EWS 0.37609 RTK 0.31017 RAM 0.9114 YAS 0.6093 UUY 0.091907 HIT 0.86842 GAE 0.049653 JCR 0.74796 XFR 0.099728 HBW 0.57591 KCR 0.83757 BDH 0.7409 BFZ 0.42555 RUO 0.59821 YZE 0.44796 DWD 0.73122 VCO 0.16344 VWM 0.037383 MLX 0.87873 SMH 0.017434 TJU 0.75425 NRY 0.16047 MWT 0.25288 UII 0.24636 GSI 0.24684 GQX 0.81866 QTB 0.92575 UKH 0.17171 NXA 0.59514 HMY 0.47891 BWP 0.33006 MMS 0.54005 PUK 0.23366 GUL 0.16528 XUV 0.89593 PTF 0.11724 DHW 0.66808 FAK 0.56991 RIF 0.40806 YKH 0.72032 QBX 0.65169 RCK 0.37414 HGJ 0.20302 MWU 0.044469 IDE 0.26088 IGL 0.04608 OKX 0.17218 KQP 0.86295 TTC 0.89668 MMY 0.54442 CNU 0.22267 XUL 0.21866 FJH 0.29 OYU 0.39635 ZTF 0.49366 KBR 0.72382 QLY 0.66791 SZA 0.94104 JDN 0.2406 AYK 0.68394 OIZ 0.39289 IUQ 0.79334 MKJ 0.4375 DWX 0.086047 UHS 0.55104 UYA 0.6523 SIB 0.21771 TMV 0.51375 TGW 0.68983 ABV 0.63904 RPN 0.81676 WQE 0.23744 EWV 0.032024 BCF 0.66718 IVP 0.36553 DTM 0.034415 HXL 0.4099 ULI 0.046987 ACY 0.78004 IBX 0.092194 NHB 0.88993 SZY 0.42605 WAD 0.023337 DGX 0.26514 PNR 0.16441 ULW 0.92011 AQP 0.067289 PWX 0.33887 HRD 0.11091 WWA 0.74279 UJC 0.7895 QIM 0.18425 BPZ 0.99524 QHV 0.93101 BLM 0.50498 JSA 0.13742 SUS 0.42711 LTZ 0.36392 XYB 0.7993 UQK 0.87342 VUT 0.40275 KXB 0.20391 FJN 0.97118 FXN 0.0045304 CCX 0.21433 OCX 0.63593 FPD 0.92674 IEM 0.4284 PAQ 0.50016 CLB 0.056519 FJQ 0.36445 GAH 0.53029 HKR 0.13843 APW 0.81967 AWW 0.26977 XGZ 0.72688 ICC 0.12335 YED 0.56258 WLA 0.57895 KBQ 0.88524 AEE 0.88456 UJJ 0.90473 XCX 0.88853 VXA 0.65325 DFY 0.49202 SVH 0.66334 GPW 0.95805 GSY 0.49196 LSP 0.21966 WHT 0.8411 UKE 0.89017 VAI 0.49843 ZMN 0.8174 ZZH 0.77544 IIT 0.89985 CDI 0.49299 XZT 0.23001 CTJ 0.18004 ZNB 0.6137 HYY 0.68227 AFT 0.84142 JDC 0.99082 PUX 0.74053 ZZK 0.068487 TOF 0.34602 JHZ 0.59807 DCO 0.43001 NTE 0.037336 QBU 0.22754 PZX 0.58027 DPS 0.16107 MIC 0.55373 WZN 0.89313 ARD 0.72757 MGN 0.9268 OSF 0.80816 FBL 0.76205 BPV 0.31799 COG 0.62676 HCI 0.89766 SMX 0.84071 LEI 0.64723 LRL 0.21707 LXF 0.1186 PZF 0.85911 FYL 0.756 GBG 0.025344 BSF 0.62353 AAF 0.69346 AUP 0.73579 VPA 0.76381 LVF 0.68136 VCH 0.14223 ZGD 0.26049 PIW 0.76516 RKF 0.085646 QAB 0.53884 BEV 0.36689 FLA 0.29688 HSJ 0.91988 NTH 0.95602 QMJ 0.003556 IVJ 0.089437 BXT 0.14233 RGU 0.72035 GGM 0.42158 QKV 0.92933 TBU 0.7958 ERC 0.46558 OQC 0.0048832 DTI 0.97489 AER 0.85489 CAX 0.13519 WJX 0.93596 POQ 0.19365 RHR 0.5455 OTB 0.1694 KJA 0.1876 AIA 0.10479 UNA 0.75074 FAR 0.31332 SLQ 0.88211 BIK 0.40504 VBT 0.42634 TOJ 0.89905 OEJ 0.40739 KSJ 0.70865 GGL 0.85946 WYM 0.37602 WFT 0.5276 SPI 0.44618 WZZ 0.11854 JCK 0.25881 CZI 0.6613 KPK 0.8764 RIJ 0.70863 MPI 0.25743 NZM 0.85593 GPG 0.7885 HKC 0.469 XCS 0.73655 RZP 0.83652 BPJ 0.24444 CPF 0.79023 BDE 0.12515 XWD 0.75409 SGR 0.92493 UUA 0.61487 IBV 0.87967 LZQ 0.22603 AZG 0.38676 RDI 0.78936 XCO 0.98904 KPH 0.24451 YJK 0.17471 SXI 0.69896 YGZ 0.55506 WTO 0.06259 JVS 0.92592 RLW 0.82327 OHO 0.94916 LBK 0.41102 OMS 0.19133 BQY 0.1612 FCM 0.47606 XED 0.74461 ZZM 0.11554 VQB 0.68961 DWC 0.60798 YVE 0.2145 PGD 0.41743 MHT 0.86142 MRK 0.65909 FMY 0.65673 KBL 0.70052 EHO 0.55105 IHN 0.1698 IZL 0.40128 GEN 0.46435 SRS 0.73956 ZYW 0.43446 WRJ 0.79841 VPJ 0.6368 TFP 0.97176 CWY 0.13262 HIR 0.077038 LHV 0.039326 CRF 0.21398 EDL 0.99523 QIO 0.89263 GCN 0.68045 YHP 0.0013947 BOU 0.40666 GZV 0.78872 QPK 0.23717 KXP 0.5118 LYG 0.39811 CUU 0.86919 IJH 0.43619 GEF 0.062934 BSR 0.72131 FOE 0.58991 WBP 0.91743 UBV 0.74054 FNL 0.7518 YVF 0.14629 GWE 0.1758 SJD 0.38881 FXW 0.50665 DJG 0.61826 IWD 0.6182 HYY 0.14286 ENI 0.67416 TYP

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!