tabledisp displays in good format a table or array in the command line
latex_string =tabledisp(T)
examplelatex_string =tabledisp(T, precision)
examplelatex_string =tabledisp(T, precision, stylerc)
examplelatex_string =tabledisp(T, precision, stylerc, filename)
example[latex_string , disp_string ]=tabledisp(___)
example[latex_string , disp_string , latex_string_full]=tabledisp(___)
exampletabledisp displays a table or o bi-dimensional array in the MATLAB command line or in a uitable and also in an excel file.
Dispay a table in MATLAB annotations.latex_string
=tabledisp(T
)
Dispay an array in a MATLAB annotation, with 6 digits of precision.latex_string
=tabledisp(T
,
precision
)
Dispay an array in a MATLAB annotation with bold row/column names.latex_string
=tabledisp(T
,
precision
,
stylerc
)
Dispay a large table in a MATLAB annotation.latex_string
=tabledisp(T
,
precision
,
stylerc
,
filename
)
[
Dispay an array in a MATLAB annotation, and save it in a specific file.latex_string
,
disp_string
]
=tabledisp(___)
[
Save an array in a excel file.latex_string
,
disp_string
,
latex_string_full
]
=tabledisp(___)
load a generic dataset
load patients; % put it in a table T = table(Age,Height,Weight,Systolic,Diastolic, ... 'RowNames',LastName); % keep just few lines, as example Tsmall = T(1:10,:); % run tabledisp [latex_string , disp_string] = tabledisp(Tsmall); % Now use the output of tabledisp to diplay the latex table in the % annotation of a figure hf = figure; annotation(hf,'Textbox','String',latex_string,... 'FitBoxToText','on','Interpreter','latex',... 'FontName',get(0,'FixedWidthFontName'),'FontSize',14,... 'Units','Normalized','Position',[0 0 1 1]); % An this is to display the table in the command window without disp fprintf(disp_string);
RAW NAME | Age | Height | Weight | Systolic | Diastolic | 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 | Davis | 46 | 68 | 142 | 121 | 70 | Miller | 33 | 64 | 142 | 130 | 88 | Wilson | 40 | 68 | 180 | 115 | 82 | Moore | 28 | 68 | 183 | 115 | 78 | Taylor | 31 | 66 | 132 | 118 | 86 |
generate data
X = 1000*randn(15,5); % and run tabledisp on them with the specification of the precision [latex_string , disp_string] = tabledisp(X,6); % This is to produce a latex table display in a figure hf = figure; annotation(hf,'Textbox','String',latex_string,... 'FitBoxToText','on','Interpreter','latex',... 'FontName',get(0,'FixedWidthFontName'),'FontSize',14,... 'Units','Normalized','Position',[0 0 1 1]); % This is to display the table in the command window without disp fprintf(disp_string);
RAW NAME | T1 | T2 | T3 | T4 | T5 | 1 | -642.6483 | -440.131 | 1,104.9006 | 245.5159 | 630.8936 | 2 | -785.1733 | 611.831 | -898.6927 | -1,345.7007 | 914.9489 | 3 | 122.9279 | 1,286.8214 | -1,514.4625 | 160.911 | 1,120.2776 | 4 | 540.7655 | -1,138.2374 | 336.7838 | -258.5461 | 620.3689 | 5 | -848.4028 | -467.4951 | 667.4101 | 592.9553 | -322.2367 | 6 | 786.2817 | 247.94 | 1,079.9811 | 464.2873 | -245.7592 | 7 | 287.5322 | -401.9775 | -472.4264 | 1,275.6469 | 603.5453 | 8 | 122.4031 | 1,278.1452 | 1,582.5452 | 1,428.7118 | -944.9186 | 9 | 570.5593 | 649.3667 | -627.858 | -1,033.6214 | -465.7345 | 10 | -2,286.3383 | -1,432.5479 | -652.1127 | 528.3495 | -940.9917 | 11 | 735.5183 | 738.2493 | -575.9439 | 1,162.0714 | 1,247.9188 | 12 | 39.0898 | -637.4955 | -238.43 | 616.8177 | 476.6604 | 13 | -1,285.6645 | -1,861.4759 | -1,411.9044 | -336.5007 | -407.7188 | 14 | 1,003.3411 | -493.8922 | -535.8223 | -521.2686 | 1,543.5716 | 15 | 98.2425 | -346.413 | 758.2655 | 1,389.8119 | 1,799.0128 |
close all % generate data X = 1000*randn(10,5); % and run tabledisp on them with the specification of the italic style [latex_string_i , disp_string] = tabledisp(X,[],'i'); hfi = figure; annotation(hfi,'Textbox','String',latex_string_i,... 'FitBoxToText','on','Interpreter','latex',... 'FontName',get(0,'FixedWidthFontName'),'FontSize',14,... 'Units','Normalized','Position',[0 0 1 1]); % and now bold style [latex_string_b , disp_string] = tabledisp(X,[],'b'); hfb = figure; annotation(hfb,'Textbox','String',latex_string_b,... 'FitBoxToText','on','Interpreter','latex',... 'FontName',get(0,'FixedWidthFontName'),'FontSize',14,... 'Units','Normalized','Position',[0 0 1 1]); cascade;
generate data
X = 1000*randn(150,5); % and run tabledisp on them with the specification of the precision [latex_string , disp_string , latex_string_full] = tabledisp(X,6,'b'); % This is to produce a latex table display in a figure hf = figure; annotation(hf,'Textbox','String',latex_string,... 'FitBoxToText','on','Interpreter','latex',... 'FontName',get(0,'FixedWidthFontName'),'FontSize',14,... 'Units','Normalized','Position',[0 0 1 1]); % This is to display the table in the command window without disp fprintf(disp_string);
RAW NAME | T1 | T2 | T3 | T4 | T5 | 1 | -787.7272 | -105.4336 | -212.8553 | -822.2839 | 1,007.8109 | 2 | 145.7277 | -1,446.6824 | 267.7369 | 885.9545 | 347.1749 | 3 | -1,234.0618 | 200.4955 | -2,516.9783 | 1,216.1634 | -2,043.326 | 4 | -530.2312 | -849.3332 | -659.7629 | 1,037.5902 | 219.8355 | 5 | 698.8208 | -148.6655 | -841.4304 | -282.0232 | 281.9986 | 6 | 1,323.5493 | -453.7822 | 397.4049 | 2,535.7121 | 378.0888 | 7 | -1,359.397 | -564.068 | 608.5418 | -1,479.8782 | -1,582.2067 | 8 | -304.3601 | -217.9376 | -1,877.976 | 687.5311 | -1,259.8771 | 9 | 390.1232 | 146.0983 | -182.7458 | -309.8405 | 2,623.5167 | 10 | 841.5163 | 751.9273 | -532.6592 | 1,516.0886 | 729.7505 | 11 | -270.5252 | 745.5922 | -435.3781 | -248.5117 | -1,880.4665 | 12 | 365.8942 | -1,258.4364 | 238.2856 | 382.2859 | 715.4604 | 13 | 168.5193 | -316.4163 | -538.7607 | 1,030.5425 | 431.2763 | 14 | -803.2765 | -389.8434 | 959.3312 | -1,880.9067 | 98.8138 | 15 | -192.2488 | 964.7351 | 1,273.4253 | -490.6264 | 2,148.3378 | 16 | 213.318 | 481.374 | 255.8227 | -1,527.2357 | -426.8742 | 17 | 54.1523 | -700.7364 | 2,073.3757 | 893.14 | -473.9764 | 18 | 270.6178 | 285.2076 | 0.8937 | 957.7365 | -794.8372 | 19 | -476.0054 | 777.2297 | 1,261.7925 | 1,560.5058 | 476.6093 | 20 | -403.7705 | 333.7388 | -1,230.3227 | 490.3638 | -121.0184 | 21 | 457.2857 | -680.1867 | 511.2413 | 1,030.9603 | 456.0972 | 22 | 1,006.6721 | -634.3394 | 134.3595 | -1,261.2998 | -844.636 | 23 | -355.5712 | 241.3546 | -411.7206 | -327.7291 | -808.7997 | 24 | 262.3942 | -269.3375 | 46.3431 | -876.7126 | 446.0055 | 25 | 738.3957 | -601.799 | 273.4306 | -1,339.7718 | 727.8403 | 26 | -1,018.5195 | -547.6582 | 25.4436 | 6.9523 | 252.4221 | 27 | 288.6231 | -1,523.8361 | -493.6129 | 663.212 | 450.0203 | 28 | -1,810.1097 | -2,108.6138 | 1,060.2633 | 732.2088 | -613.8941 | 29 | -1,270.0414 | -533.2683 | -92.9141 | 1,310.8321 | -870.5159 | 30 | -146.4204 | -1,337.8483 | 1,059.0978 | 184.3356 | -704.4731 | 31 | -366.4107 | 1,486.4144 | 1,145.3949 | -7.004 | 703.0654 | 32 | 1,346.0791 | -100.9444 | 1,349.484 | 1,054.1038 | -1,126.8082 | 33 | -371.1778 | 172.3045 | -648.3001 | -1,069.7636 | 397.6466 | 34 | -1,042.4469 | -763.9893 | -768.279 | -392.816 | 385.9951 | 35 | 991.1138 | 321.6884 | 719.0246 | -937.0189 | -1,308.9186 | 36 | 1,447.5495 | -903.2946 | -908.89 | 779.0495 | 800.698 | 37 | 2,611.7918 | 898.1555 | -121.3638 | -311.2915 | 289.3547 | 38 | 1,567.3133 | -802.3063 | -157.1821 | -848.8836 | -850.9258 | 39 | -690.8467 | 1,683.7911 | 904.2799 | 657.4816 | -572.5359 | 40 | -338.132 | 1,689.2121 | -390.3257 | 845.4725 | 395.4265 | 41 | -2,084.8739 | -114.1304 | 88.5632 | -1,003.2844 | -3,236.1388 | 42 | 854.8725 | 275.0933 | -534.7742 | 607.4791 | -84.0263 | 43 | -28.1698 | 202.3703 | -465.4914 | 1,334.1469 | -211.0004 | 44 | 260.0125 | 902.1513 | -1,043.9565 | -840.6991 | 3.6217 | 45 | 1,725.1793 | -492.3056 | -842.5416 | -611.6521 | 1,020.6816 | 46 | -610.2184 | -345.6312 | -259.8981 | -1,043.9688 | 409.8866 | 47 | -584.1243 | 137.7774 | -1,078.9242 | 245.6193 | -277.5397 | 48 | 104.4695 | 997.1502 | -19.6526 | -1,979.3026 | -731.1334 | 49 | -1,322.2528 | 90.7536 | -469.5995 | 47.2512 | 351.6155 | 50 | 1,332.832 | -191.747 | -889.6667 | -1,135.9462 | -1,605.2138 | 51 | 268.1105 | 2,825.1633 | -996.6031 | 512.5044 | -1,347.0337 | 52 | -163.4915 | -255.9702 | -116.4501 | 292.1781 | 283.598 | 53 | 1,338.4004 | -225.4258 | -146.0214 | 1,717.9184 | 1,282.0434 | 54 | 1,036.0626 | -1,047.7063 | -732.1785 | 1,500.1966 | 1,558.7364 | 55 | 1,332.9321 | 2,154.154 | 759.6499 | -1,110.0294 | 529.8753 | 56 | 682.8967 | 401.1379 | -474.2863 | -928.747 | 311.3829 | 57 | -169.5456 | -681.5778 | -980.5159 | 866.2692 | -1,066.0154 | 58 | 402.2696 | 655.8332 | -674.2037 | 865.2815 | 294.3756 | 59 | 184.5057 | -744.3286 | -207.0234 | -563.116 | 1,041.1347 | 60 | 35.9026 | -209.0124 | -215.6366 | 361.7048 | -88.8122 | 61 | 521.3333 | -644.3896 | 616.4343 | -491.691 | 198.6861 | 62 | 158.4549 | -543.07 | 119.4031 | -22.0374 | -160.77 | 63 | -341.7486 | -2,187.787 | 981.7279 | -65.3593 | -364.8443 | 64 | 137.6752 | -1,895.2729 | -509.5842 | -762.2291 | 581.6662 | 65 | -1,201.8477 | 907.8493 | -697.8803 | 820.5422 | -2,365.1776 | 66 | 939.2803 | 870.411 | 232.2644 | -503.6471 | -1,120.7208 | 67 | 2,177.2279 | -1,937.7006 | 1,010.8916 | 260.5957 | 814.1283 | 68 | 256.0317 | -1,180.2724 | -422.9378 | -314.9483 | -1,890.4392 | 69 | 827.3424 | 643.4561 | 236.8249 | -1,238.3884 | 562.8804 | 70 | 2,548.3195 | 900.9484 | 821.0387 | -525.6993 | -1,038.6917 | 71 | 295.328 | -1,072.1548 | 264.9007 | -937.8844 | 1,430.2065 | 72 | 1,092.3397 | 283.4396 | -615.2186 | -71.8719 | 1,257.6751 | 73 | -320.7394 | -936.3813 | 1,319.4931 | -107.2884 | 1,112.8217 | 74 | 1,584.605 | 483.5211 | 194.4678 | -491.5983 | -2,321.6029 | 75 | 52.1724 | -1,183.2539 | 523.6801 | 504.4477 | 583.8817 | 76 | 646.625 | 314.6115 | 458.4679 | 103.5436 | -76.4381 | 77 | 2,437.6 | -627.4697 | -1,793.6287 | -1,642.7121 | -204.1584 | 78 | 1,209.0249 | -1,476.4945 | -1,032.1492 | -1,346.4316 | 464.447 | 79 | -1,408.9932 | -497.8334 | -111.8274 | -1,352.7013 | -178.9873 | 80 | -95.8056 | -861.1069 | 1,335.2105 | -1,068.2862 | -616.9706 | 81 | 839.1656 | -141.6596 | 702.3931 | 1,309.3556 | -1,089.457 | 82 | 1,506.2196 | -828.4267 | 869.422 | 888.2539 | -128.4346 | 83 | 1,378.152 | -40.0172 | 1,797.167 | -13.737 | 537.1057 | 84 | -1,721.4635 | 1,196.0634 | 437.0512 | -468.3335 | 1,383.7764 | 85 | -555.3442 | 1,339.2178 | -1,136.6553 | -811.5534 | -12.9164 | 86 | -1,601.1385 | -2,031.9949 | 263.5095 | 1,970.355 | 318.186 | 87 | 960.733 | 1,593.9753 | -1,385.2038 | 509.5945 | 825.0738 | 88 | -337.3728 | 1,761.6306 | -440.4951 | 1,541.7903 | 206.347 | 89 | -1,956.9763 | 537.6228 | 893.6833 | 34.3483 | -1,816.5814 | 90 | 1,574.8733 | 1,085.3254 | -1,721.3816 | 748.0108 | 1,060.7421 | 91 | 1,597.669 | -297.1519 | -1,216.5194 | 1,258.7938 | -567.7434 | 92 | -337.898 | -87.912 | 2,345.6837 | 716.6964 | 675.2636 | 93 | -511.8424 | -1,207.4346 | 415.3681 | 84.7718 | -361.0832 | 94 | -1,118.4096 | -1,185.044 | 181.1242 | -1,243.5008 | 1,920.9904 | 95 | 520.5562 | -1,968.5587 | 93.2307 | 1,142.1763 | 864.656 | 96 | 250.49 | -1,425.6364 | 1,803.1518 | -371.8141 | -1,589.7388 | 97 | -28.7972 | 604.3097 | -1,341.3708 | -1,312.7087 | 843.8497 | 98 | 195.146 | 256.4128 | -602.3477 | 728.1066 | 161.0809 | 99 | 1,236.5158 | -932.0008 | -144.9559 | -422.7073 | 966.1022 | 100 | 643.8307 | -313.7225 | 1,196.185 | -1,697.0304 | 765.758 | 101 | 973.626 | 1,087.5323 | -344.1507 | -1,016.8277 | 61.6855 | 102 | -30.3561 | -77.4894 | 129.0838 | 282.2442 | -396.7508 | 103 | 1,265.3503 | 297.2984 | 145.6075 | 447.2389 | 213.7883 | 104 | -355.3825 | 595.8956 | -454.7487 | 976.4772 | -923.0705 | 105 | 1,764.6368 | -1,622.244 | 51.6649 | 374.201 | -1,086.6321 | 106 | -108.8216 | 133.6218 | -382.6911 | 786.3283 | 1,907.6977 | 107 | 571.4248 | -671.6248 | -237.2078 | -251.3433 | 631.9267 | 108 | 856.4329 | 1,278.078 | 1,312.7856 | -273.0422 | 2,206.3224 | 109 | 1,064.2914 | 412.0266 | 1,570.2171 | -886.4907 | 69.8444 | 110 | -172.4738 | 657.0036 | -111.558 | 1,347.9215 | 1,275.9635 | 111 | -566.4381 | 859.7472 | -449.2904 | 2,266.9341 | -75.9976 | 112 | 1,164.5764 | 649.1212 | 164.6557 | 157.5779 | 833.7464 | 113 | -1,667.7928 | -1,748.7217 | 1,258.7968 | 525.365 | -55.9843 | 114 | -1,135.7831 | -639.7413 | -671.3992 | 1,461.7439 | -812.71 | 115 | 464.8612 | 1,054.2988 | -1,088.1274 | -2,461.2179 | -460.4166 | 116 | -776.2392 | 742.7353 | 240.7301 | 419.3991 | -135.637 | 117 | -321.3708 | -5.3308 | -926.4101 | -318.5993 | 111.3505 | 118 | -689.6241 | 1,852.7373 | -365.1664 | 1,185.9028 | 92.9888 | 119 | 371.1536 | 239.3883 | -1,761.3347 | -1,267.2679 | -509.3824 | 120 | -167.2871 | 1,454.1069 | 310.9854 | -593.7995 | 265.335 | 121 | 1,295.9848 | 153.987 | 1,781.4711 | -2,049.6337 | 53.1553 | 122 | 189.7191 | -532.4159 | -166.7716 | 597.8087 | 2,613.0003 | 123 | 574.2162 | 604.6868 | 773.8884 | -502.3618 | 479.2002 | 124 | -1,871.1286 | 905.2834 | 878.4116 | 788.9539 | 1,044.7349 | 125 | 364.2317 | 277.4487 | -718.9019 | 729.6869 | 591.4073 | 126 | 1,080.9994 | -656.9904 | 160.6196 | 979.8949 | -32.3987 | 127 | 785.6036 | 1,875.6846 | 489.8627 | 1,258.6633 | 626.6488 | 128 | 305.4752 | 37.1407 | 230.6743 | -68.0968 | 582.5854 | 129 | -38.3236 | -2,237.9114 | 776.0483 | -1,348.0624 | -630.9096 | 130 | 1,105.9182 | 69.6908 | 1,894.4291 | -1,099.4619 | -533.8821 | 131 | 1,407.3082 | -147.9813 | -1,328.2665 | -390.6768 | 289.1322 | 132 | -519.7642 | 851.0246 | -3,481.7056 | -334.3874 | -244.7611 | 133 | -1,035.6193 | 137.0727 | 1,393.8881 | 397.2906 | 262.7366 | 134 | -99.6135 | 487.4364 | -1,073.0816 | 572.2264 | 593.0614 | 135 | -448.44 | 228.6037 | 259.84 | -2,032.3327 | -2,238.5202 | 136 | -277.9804 | -126.898 | -61.4717 | 271.787 | 954.1276 | 137 | -940.1041 | 2,305.1628 | 104.3811 | -213.3919 | 2,811.0306 | 138 | 1,063.6807 | -511.1828 | 345.4076 | -856.2617 | -919.6765 | 139 | -1,622.3156 | 811.0956 | 1,155.9032 | 240.4376 | 40.4149 | 140 | -133.3518 | -1,694.3598 | 1,547.8449 | -250.5645 | 928.4667 | 141 | -703.5562 | 892.0885 | -537.8299 | 1,069.198 | 33.1609 | 142 | 674.6875 | -1,990.0994 | 1,042.6121 | -73.7352 | 1,314.9017 | 143 | -49.6924 | 699.1429 | 447.8803 | -344.6807 | -1,124.6818 | 144 | -821.7271 | 1,582.1731 | -1,604.4585 | 177.6716 | -158.9919 | 145 | 1,343.4573 | -1,790.9254 | -236.9001 | 507.3292 | -1,044.4349 | 146 | 295.7457 | -1,640.1059 | 1,171.8848 | -761.8483 | -641.6653 | 147 | 1,457.7564 | 1,658.546 | 36.8715 | 276.7947 | 216.4206 | 148 | 1,225.8398 | 117.8477 | 257.1042 | 540.1497 | 234.2318 | 149 | 898.5096 | 350.0252 | 1,918.6865 | -1,328.6838 | 234.3443 | 150 | 802.7712 | 217.6202 | -545.7429 | 24.0498 | -215.5474 |
X = randn(10,5); % and run tabledisp on them with the specification of the precision [latex_string , disp_string] = tabledisp(X,2,'','myfile.txt');
X = randn(10,5); % and run tabledisp on them with the specification of the precision % An excel file named tabledisp_excel.xlsx is created in the current folder. [latex_string , disp_string] = tabledisp(X,2,'','excel');
T
— Input table.
Table or bi-dimensional array.The table/array contains a data matrix with n observations on v variables.
Missing values (NaN's) and infinite values (Inf's) are allowed.
Data Types: single| double
precision
— Number of digits after the comma, to display.
Scalar.An integer value.
Example: 'precision',2
Data Types: single|double
stylerc
— The display style of the raw and column names.
Character
array.It can take these values: 'b' which stands for bold;
'i' which stands for italic;
'n' which stand for normal (the default).
If the user mis-specify the style, 'n is used.
Example: 'stylerc','b'
Data Types: char
filename
— The name of a file where the formatted table will be saved.
Array of characters.A filename without empty spaces. Note that the latex string in the file contains the proper \n characters and can be easily incorporated in latex documents. If filename is 'excel', then an excel file is generated with the fixed name 'tabledisp_excel.xlsx'.
Example: 'filename','pippo.txt'
Data Types: char
latex_string
—Latex string with table display.
Character arrayThe string can be used in uitables, annotation statements or other matlab tools receving latex sentences. Note that this string by default has no \n characters, as they are not treated by the annotation statement. Note also that this string is automatically and appropriately cut to comply with the 1200 characters limitaion of annotations and latex statements in graphical objects.
disp_string
—String with table display.
Character arrayThe string can be displayed in the command window with fprintf(disp_string).
latex_string_full
—Latex string with table display.
Character arrayThis is the full version of latex_string, without the cut on 1200 characters. It is reported in output in case there is a need to copy-paste the full table in LaTeX documents.
Lamport, L. (1994), LATEX: a document preparation system: user's guide and reference manual. Addison-Wesley Longman Publishing Co., Inc., USA.