1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344
|
% =========================================================================
% *** FUNCTION testfunctions
% ***
% *** Standard example plot from MATLAB's help pages.
% ***
% =========================================================================
% ***
% *** Copyright (c) 2008--2014, Nico Schlรถmer <nico.schloemer@gmail.com>
% *** All rights reserved.
% ***
% *** Redistribution and use in source and binary forms, with or without
% *** modification, are permitted provided that the following conditions are
% *** met:
% ***
% *** * Redistributions of source code must retain the above copyright
% *** notice, this list of conditions and the following disclaimer.
% *** * Redistributions in binary form must reproduce the above copyright
% *** notice, this list of conditions and the following disclaimer in
% *** the documentation and/or other materials provided with the distribution
% ***
% *** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% *** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% *** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% *** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% *** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% *** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% *** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% *** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% *** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% *** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% *** POSSIBILITY OF SUCH DAMAGE.
% ***
% =========================================================================
function [desc, extraOpts, extraCFOptions, funcName, numFunctions] = testfunctions(k)
% assign the functions to test
testfunction_handles = { ...
@one_point , ...
@plain_cos , ...
@sine_with_markers , ...
@markerSizes , ...
@markerSizes2 , ...
@sine_with_annotation, ...
@linesWithOutliers , ...
@peaks_contour , ...
@contourPenny , ...
@peaks_contourf , ...
@many_random_points , ...
@double_colorbar , ...
@subplot_colorbar , ...
@randomWithLines , ...
@double_axes , ...
@double_axes2 , ...
@logplot , ...
@colorbarLogplot , ...
@legendplot , ...
@legendplotBoxoff , ...
@moreLegends , ...
@zoom , ...
@quiveroverlap , ...
@quiverplot , ...
@quiver3plot , ...
@imageplot , ...
@logicalImage , ...
@imagescplot , ...
@imagescplot2 , ...
@stairsplot , ...
@polarplot , ...
@roseplot , ...
@compassplot , ...
@stemplot , ...
@stemplot2 , ...
@groupbars , ...
@bars , ...
@subplotBars , ...
@hbars , ...
@stackbars , ...
@xAxisReversed , ...
@errorBars , ...
@errorBars2 , ...
@subplot2x2 , ...
@subplot2x2b , ...
@manualAlignment , ...
@subplot3x1 , ...
@subplotCustom , ...
@legendsubplots , ...
@legendsubplots2 , ...
@bodeplots , ...
@rlocusPlot , ...
@mandrillImage , ...
@besselImage , ...
@clownImage , ...
@zplanePlot1 , ...
@zplanePlot2 , ...
@freqResponsePlot , ...
@axesLocation , ...
@axesColors , ...
@multipleAxes , ...
@scatterPlotRandom , ...
@scatterPlot , ...
@scatter3Plot , ...
@scatter3Plot2 , ...
@spherePlot , ...
@surfPlot , ...
@surfPlot2 , ...
@superkohle , ...
@meshPlot , ...
@ylabels , ...
@spectro , ... % takes pretty long to LuaLaTeX-compile
@mixedBarLine , ...
@decayingharmonic , ...
@texcolor , ...
@textext , ...
@texrandom , ...
@latexmath1 , ...
@latexmath2 , ...
@parameterCurve3d , ...
@parameterSurf , ...
@fill3plot , ...
@rectanglePlot , ...
@herrorbarPlot , ...
@hist3d , ...
@myBoxplot , ...
@areaPlot , ...
@customLegend , ...
@pixelLegend , ...
@croppedImage , ...
@doubleAxes , ...
@pColorPlot , ...
@hgTransformPlot , ...
@scatter3Plot3 , ...
@scatterPlotMarkers , ...
@multiplePatches , ...
@logbaseline , ...
@alphaImage
};
numFunctions = length( testfunction_handles );
desc = '';
funcName = '';
extraOpts = {};
extraCFOptions = {};
if (k<=0)
return; % This is used for querying numFunctions.
elseif (k<=numFunctions)
funcName = func2str(testfunction_handles{k});
try
nargs = nargout(funcName);
catch %#ok
% In Octave 3.6.4, `nargout` seems not to be able to handle
% everything as MATLAB does:
% * it does not support function handles (so using strings)
% * it cannot handle subfunctions apparently, so always use the
% default syntax there
%TODO: handle diferent number of arguments in Octave
warning('testfunctions:nargoutOctave',...
'Cannot determine number of output of "%s". Assuming 2.',funcName)
nargs = 2;
end
switch nargs
case 3
[desc, extraOpts, extraCFOptions] = testfunction_handles{k}();
case 1
desc = testfunction_handles{k}();
otherwise
[desc, extraOpts] = testfunction_handles{k}();
end
else
error('testfunctions:outOfBounds', ...
'Out of bounds (number of testfunctions=%d)', numFunctions);
end
return;
end
% =========================================================================
function [description, extraOpts] = one_point()
m = [0 1 1.5 1 -1];
k = 1:1:length(m);
plot(k,m,'*-');
title({'title', 'multline'})
%legend(char('Multi-Line Legend Entry','Wont Work 2^2=4'))
legend('Multi-Line Legend Entry Wont Work 2^2=4')
xlabel({'one','two','three'});
ylabel({'one','ยฐ โ', 'three'});
set(gca, 'YTick', []);
set(gca,'XTick',0:1:length(m)-1);
set(gca,'XTickLabel',{});
description = 'Plot only one single point.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts, extraOptsCleanFigure] = plain_cos()
fplot( @cos, [0,2*pi] );
% add some minor ticks
set(gca, 'XMinorTick', 'on');
set(gca, 'YTick', []);
% Adjust the aspect ratio when in MATLAB(R) or Octave >= 3.4.
env = getEnvironment();
switch env
case 'MATLAB'
daspect([ 1 2 1 ])
case 'Octave'
if isVersionBelow( env, 3, 4 )
% Octave < 3.4 doesn't have daspect unfortunately.
else
daspect([ 1 2 1 ])
end
otherwise
error( 'Unknown environment. Need MATLAB(R) or GNU Octave.' )
end
description = 'Plain cosine function with minimumPointsDistance of $0.5$.' ;
extraOpts = {};
extraOptsCleanFigure = {'minimumPointsDistance', 0.5};
end
% =========================================================================
function [description, extraOpts] = sine_with_markers ()
% Standard example plot from MATLAB's help pages.
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
y(3) = NaN;
y(7) = Inf;
y(11) = -Inf;
plot(x,y,'--o', 'Color', [0.6,0.2,0.0], ...
'LineWidth', 1*360/127,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0.3,0.1,0.0],...
'MarkerSize', 5*360/127 );
set( gca, 'Color', [0.9 0.9 1], ...
'XTickLabel', [], ...
'YTickLabel', [] ...
);
set(gca,'XTick',[0]);
set(gca,'XTickLabel',{'null'});
description = [ 'Twisted plot of the sine function. ' ,...
'Pay particular attention to how markers and Infs/NaNs are treated.' ];
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = markerSizes()
hold on;
h = fill([1 1 2 2],[1 2 2 1],'r');
set(h,'LineWidth',10);
plot([0],[0],'go','Markersize',14,'LineWidth',10)
plot([0],[0],'bo','Markersize',14,'LineWidth',1)
description = 'Marker sizes.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = markerSizes2()
hold on;
grid on;
n = 1:10;
d = 10;
s = round(linspace(6,25,10));
e = d * ones(size(n));
style = {'bx','rd','go','c.','m+','y*','bs','mv','k^','r<','g>','cp','bh'};
nStyles = numel(style);
for ii = 1:nStyles
for jj = 1:10
plot(n(jj), ii * e(jj),style{ii},'MarkerSize',s(jj));
end
end
xlim([min(n)-1 max(n)+1]);
ylim([0 d*(nStyles+1)]);
set(gca,'XTick',n,'XTickLabel',s,'XTickLabelMode','manual');
description = 'Line plot with with different marker sizes.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = sine_with_annotation ()
x = -pi:.1:pi;
y = sin(x);
h = plot(x,y);
set(gca,'XTick',-pi:pi/2:pi);
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'});
xlabel('-\pi \leq \Theta \leq \pi');
ylabel('sin(\Theta)');
title({'Plot of sin(\Theta)','subtitle','and here''s one really long subtitle' });
text(-pi/4,sin(-pi/4),'\leftarrow sin(-\pi\div4)',...
'HorizontalAlignment','left');
set(findobj(gca,'Type','line','Color',[0 0 1]),...
'Color','red',...
'LineWidth',10);
description = [ 'Plot of the sine function. ' ,...
'Pay particular attention to how titles and annotations are treated.' ];
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = linesWithOutliers()
far = 200;
x = [ -far, -1, -1, -far, -10, -0.5, 0.5, 10, far, 1, 1, far, 10, 0.5, -0.5, -10, -far ];
y = [ -10, -0.5, 0.5, 10, far, 1, 1, far, 10, 0.5, -0.5, -10, -far, -1, -1, -far, -0.5 ];
plot( x, y,'o-');
axis( [-2,2,-2,2] );
description = 'Lines with outliers.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = peaks_contour()
[C, h] = contour(peaks(20),10);
clabel(C, h);
% remove y-ticks
set(gca,'YTickLabel',[]);
set(gca,'YTick',[]);
colormap winter;
description = 'Test contour plots.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = contourPenny()
if ~exist('penny.mat','file')
fprintf( 'penny data set not found. Abort.\n\n' );
description = [];
extraOpts = {};
return;
end
load penny;
contour(flipud(P));
axis square;
description = 'Contour plot of a US\$ Penny.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = peaks_contourf ()
contourf(peaks(20), 10);
colorbar();
legend('my legend');
% colorbar('NorthOutside');
% colorbar('SouthOutside');
% colorbar('WestOutside');
% colormap([0:0.1:1; 1:-0.1:0; 0:0.1:1]')
colormap hsv;
description = 'Test the contourfill plots.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = double_colorbar()
vspace = linspace(-40,40,20);
speed_map = rand(20);
Q1_map = rand(20);
subplot(1, 2, 1);
contour(vspace(9:17),vspace(9:17),speed_map(9:17,9:17),20)
colorbar
axis tight
axis square
xlabel('$v_{2d}$')
ylabel('$v_{2q}$')
subplot(1, 2, 2)
contour(vspace(9:17),vspace(9:17),Q1_map(9:17,9:17),20)
colorbar
axis tight
axis square
xlabel('$v_{2d}$')
ylabel('$v_{2q}$')
description = 'Double colorbar.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = subplot_colorbar()
img = rand(100);
vec = rand(100,1);
subplot(2,1,1);
imagesc(img,[0 1]);
colorbar;
subplot(2,1,2);
plot(vec);
description = 'Subplot colorbar.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = randomWithLines()
X = randn(150,2);
X(:,1) = (X(:,1) * 90) + 75;
plot(X(:,1),X(:,2),'o');
hold on;
M(1)=min(X(:,1));
M(2)=max(X(:,1));
plot(M,[mean(X(:,2)) mean(X(:,2))],'k-');
plot(M,[2*std(X(:,2)) 2*std(X(:,2))],'k--');
plot(M,[-2*std(X(:,2)) -2*std(X(:,2))],'k--');
axis('tight');
description = 'Random points with lines.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = many_random_points ()
n = 1e3;
xy = rand(n,2);
plot ( xy(:,1), xy(:,2), '.r' );
axis([ 0, 1, 0, 1 ])
description = 'Test the performance when drawing many points.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = double_axes()
dyb = 0.1; % normalized units, bottom offset
dyt = 0.1; % separation between subsequent axes bottoms
x = [0; 24; 48; 72; 96;];
y = [7.653 7.473 7.637 7.652 7.651];
figure(1)
grid on
h1 = plot(x,y,'Color','k');
% following code is taken from `floatAxisX.m'
% get position of axes
allAxes = get(gcf,'Children');
naxes = length(allAxes);
ax1Pos = get(allAxes(naxes),'position');
% rescale and reposition all axes to handle additional axes
for an=1:naxes-1
if isequal(rem(an,2),0)
% even ones in array of axes handles represent axes on which lines are plotted
set(allAxes(an),'Position',[ax1Pos(1,1) ax1Pos(1,2)+dyb ax1Pos(1,3) ax1Pos(1,4)-dyt])
else
% odd ones in array of axes handles represent axes on which floating x-axss exist
axPos = get(allAxes(an),'Position');
set(allAxes(an),'Position',[axPos(1,1) axPos(1,2)+dyb axPos(1,3) axPos(1,4)])
end
end
% first axis a special case (doesn't fall into even/odd scenario of figure children)
set(allAxes(naxes),'Position',[ax1Pos(1,1) ax1Pos(1,2)+dyb ax1Pos(1,3) ax1Pos(1,4)-dyt])
ylimit1 = get(allAxes(naxes),'Ylim');
% get new position for plotting area of figure
ax1Pos = get(allAxes(naxes),'position');
% axis to which the floating axes will be referenced
ref_axis = allAxes(1);
refPosition = get(ref_axis,'position');
% overlay new axes on the existing one
ax2 = axes('Position',ax1Pos);
% plot data and return handle for the line
hl1 = plot(x,y,'k');
% make the new axes invisible, leaving only the line visible
set(ax2,'visible','off','ylim',ylimit1)
% set the axis limit mode so that it does not change if the
% user resizes the figure window
set(ax2,'xLimMode','manual')
% set up another set of axes to act as floater
ax3 = axes('Position',[refPosition(1) refPosition(2)-dyb refPosition(3) 0.01]);
set(ax3,'box','off','ycolor','w','yticklabel',[],'ytick',[])
set(ax3,'XMinorTick','on','color','none','xcolor',get(hl1,'color'))
xlabel('secondary axis')
description = 'Double axes';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = double_axes2()
ah1=axes;
ph=plot([0 1],[0 1]);
title('Title')
ylabel('y')
xlabel('x')
% add a new set of axes
% to make a gray grid
ah2=axes;
% make the background transparent
set(ah1,'color','none')
% move these axes to the back
set(gcf,'Child',flipud(get(gcf,'Children')))
description = 'Double overlayed axes with a flip.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = logplot()
x = logspace(-1,2);
loglog(x,exp(x),'-s')
grid on;
description = 'Test logscaled axes.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = colorbarLogplot()
switch getEnvironment()
case 'MATLAB'
imagesc([1 10 100]);
case 'Octave'
% TODO find out what to do for octave here
description = 'Logscaled colorbar -- unavailable in Octave.';
extraOpts = {};
return;
otherwise
error( 'Unknown environment. Need MATLAB(R) or Octave.' )
end
set(colorbar(), 'YScale', 'log');
description = 'Logscaled colorbar.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = legendplot()
% x = -pi:pi/20:pi;
% plot(x,cos(x),'-ro',x,sin(x),'-.b');
% h = legend('one pretty long legend cos_x','sin_x',2);
% set(h,'Interpreter','none');
x = 0:0.01:2*pi;
plot( x, sin(x), 'b', ...
x, cos(x), 'r' );
xlim( [0 2*pi] )
ylim( [-0.9 0.9] )
title( '{tikz test}' )
xlabel( '{x-Values}' )
ylabel( '{y-Values}' )
legend( 'sin(x)', 'cos(x)', 'Location','NorthOutside', ...
'Orientation', 'Horizontal' );
grid on;
description = 'Test inserting of legends.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = legendplotBoxoff ()
x = -pi:pi/20:pi;
plot( x, cos(x),'-ro',...
x, sin(x),'-.b' ...
);
h = legend( 'cos_x', 'one pretty long legend sin_x', 2 );
set( h, 'Interpreter', 'none' );
legend boxoff;
description = 'Test inserting of legends.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = moreLegends()
x = 0:.1:7;
y1 = sin(x);
y2 = cos(x);
[ax,h1,h2] = plotyy(x,y1,x,y2);
legend([h1;h2],'Sine','Cosine');
description = 'More legends.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = zoom()
fplot( @sin, [0,2*pi], '-*' );
hold on;
delta = pi/10;
plot( [pi/2, pi/2], [1-2*delta, 1+2*delta], 'r' ); % vertical line
plot( [pi/2-2*delta, pi/2+2*delta], [1, 1], 'g' ); % horizontal line
% diamond
plot( [ pi/2-delta, pi/2 , pi/2+delta, pi/2 , pi/2-delta ], ...
[ 1 , 1-delta, 1, 1+delta, 1 ], 'y' );
% boundary lines with markers
plot([ pi/2-delta, pi/2 , pi/2+delta, pi/2+delta pi/2+delta, pi/2, pi/2-delta, pi/2-delta ], ...
[ 1-delta, 1-delta, 1-delta, 1, 1+delta, 1+delta, 1+delta, 1 ], ...
'ok', ...
'MarkerSize', 20, ...
'MarkerFaceColor', 'g' ...
);
hold off;
axis([pi/2-delta, pi/2+delta, 1-delta, 1+delta] );
description = 'Plain cosine function, zoomed in.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = bars()
bins = -0.5:0.1:0.5;
bins = 10 * bins;
numEntries = length(bins);
numBars = 3;
data = round(100 * rand(numEntries, numBars));
b = bar(bins,data, 1.5);
set(b(1),'FaceColor','m','EdgeColor','none')
description = 'Plot with bars.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = subplotBars()
subplot(2,1,1);
X = rand(1,10);
bar(X);
subplot(2,1,2);
bins = -0.5:0.1:0.5;
bins = 10 * bins;
numEntries = length(bins);
numBars = 3;
data = round(100 * rand(numEntries, numBars));
bar(bins,data, 1.5);
description = 'Bars in subplots.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = hbars()
y = [75.995 91.972 105.711 123.203 131.669 ...
150.697 179.323 203.212 226.505 249.633 281.422];
barh(y);
description = 'Horizontal bars.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = groupbars()
X = [1,2,3,4,5];
Y = round(rand(5,2)*20);
% bar(X,Y,'group','BarWidth',1.0);
makebars(X,Y,1.0,'grouped');
% set(gca,'XTick',[4,4.2,4.25,4.3,4.4,4.45,4.5]);
title 'Group';
description = 'Plot with bars in groups.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = stackbars()
Y = round(rand(5,3)*10);
bar(Y,'stack');
title 'Stack';
description = 'Plot of stacked bars.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = stemplot()
x = 0:25;
y = [exp(-.07*x).*cos(x);
exp(.05*x).*cos(x)]';
h = stem(x, y);
legend( 'exp(-.07x)*cos(x)', 'exp(.05*x)*cos(x)', 'Location', 'NorthWest');
set(h(1),'MarkerFaceColor','blue')
set(h(2),'MarkerFaceColor','red','Marker','square')
description = 'A simple stem plot.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = stemplot2()
x = 0:25;
y = [exp(-.07*x).*cos(x);
exp(.05*x).*cos(x)]';
h = stem(x, y, 'filled');
legend( 'exp(-.07x)*cos(x)', 'exp(.05*x)*cos(x)', 'Location', 'NorthWest');
description = 'Another simple stem plot.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = stairsplot()
x = linspace(-2*pi,2*pi,40);
stairs(x,sin(x))
description = 'A simple stairs plot.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = quiverplot()
[X,Y] = meshgrid(-2:.2:2);
Z = X.*exp(-X.^2 - Y.^2);
[DX,DY] = gradient(Z,.2,.2);
contour(X,Y,Z);
hold on
quiver(X,Y,DX,DY);
colormap hsv;
hold off
description = 'A combined quiver/contour plot of $x\exp(-x^2-y^2)$.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = quiver3plot()
vz = 10; % Velocity
a = -32; % Acceleration
t = 0:.1:1;
z = vz*t + 1/2*a*t.^2;
vx = 2;
x = vx*t;
vy = 3;
y = vy*t;
u = gradient(x);
v = gradient(y);
w = gradient(z);
scale = 0;
quiver3(x,y,z,u,v,w,scale)
view([70 18])
description = 'Three-dimensional quiver plot.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = quiveroverlap ()
x = [0 1];
y = [0 0];
u = [1 -1];
v = [1 1];
quiver(x,y,u,v);
description = 'Quiver plot with avoided overlap.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = polarplot ()
t = 0:.01:2*pi;
polar(t,sin(2*t).*cos(2*t),'--r')
description = 'A simple polar plot.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = roseplot ()
theta = 2*pi*rand(1,50);
rose(theta);
description = 'A simple rose plot.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = compassplot ()
Z = eig(randn(20,20));
compass(Z);
description = 'A simple compass plot.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = imageplot ()
n = 10;
density = 0.5;
subplot(1,2,1);
A = sprand( n, n, density );
imagesc( A );
subplot(1,2,2);
A = sprand( n, n, density );
imagesc( A );
description = 'An image plot of matrix values.' ;
%extraOpts = {'imagesAsPng', false};
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = logicalImage()
data = rand(10,10);
imagesc(data > 0.5);
description = 'An image plot of logical matrix values.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = imagescplot()
pointsX = 10;
pointsY = 20;
x = 0:1/pointsX:1;
y = 0:1/pointsY:1;
z = sin(x)'*cos(y);
imagesc(x,y,z);
description = 'An imagesc plot of $\sin(x)\cos(y)$.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = imagescplot2()
a=magic(10);
x=-5:1:4;
y=10:19;
imagesc(x,y,a)
xlim([-3,2])
ylim([12,15])
grid on;
description = 'A trimmed imagesc plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = xAxisReversed ()
n = 100;
x = (0:1/n:1);
y = exp(x);
plot(x,y);
set(gca,'XDir','reverse');
set(gca,'YDir','reverse');
legend( 'Location', 'SouthWest' );
description = 'Reversed axes with legend.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = subplot2x2 ()
x = (1:5);
subplot(2,2,1);
y = rand(1,5);
plot(x,y);
subplot(2,2,2);
y = rand(1,5);
plot(x,y);
subplot(2,2,3);
y = rand(1,5);
plot(x,y);
subplot(2,2,4);
y = rand(1,5);
plot(x,y);
description = 'Four aligned subplots on a $2\times 2$ subplot grid.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = subplot2x2b ()
x = (1:5);
subplot(2,2,1);
y = rand(1,5);
plot(x,y);
subplot(2,2,2);
y = rand(1,5);
plot(x,y);
subplot(2,2,3:4);
y = rand(1,5);
plot(x,y);
description = 'Three aligned subplots on a $2\times 2$ subplot grid.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = manualAlignment()
xrange = linspace(-3,4,2*1024);
axes('Position', [0.1 0.1 0.85 0.15]);
plot(xrange);
ylabel('$n$');
xlabel('$x$');
axes('Position', [0.1 0.25 0.85 0.6]);
plot(xrange);
set(gca,'XTick',[]);
description = 'Manually aligned figures.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = subplot3x1 ()
x = (1:5);
subplot(3,1,1);
y = rand(1,5);
plot(x,y);
subplot(3,1,2);
y = rand(1,5);
plot(x,y);
subplot(3,1,3);
y = rand(1,5);
plot(x,y);
description = 'Three aligned subplots on a $3\times 1$ subplot grid.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = subplotCustom ()
x = (1:5);
y = rand(1,5);
subplot( 'Position', [0.05 0.1 0.3 0.3] )
plot(x,y);
y = rand(1,5);
subplot( 'Position', [0.35 0.5 0.3 0.3] )
plot(x,y);
y = rand(1,5);
subplot( 'Position', [0.65 0.1 0.3 0.3] )
plot(x,y);
description = 'Three customized aligned subplots.' ;
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = errorBars ()
data = 1:10;
eH = rand(10,1);
eL = rand(10,1);
%hold on;
%bar(1:10, data)
errorbar(1:10, data, eL, eH, '.')
description = 'Generic error bar plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = errorBars2 ()
data = load( 'myCount.dat' );
y = mean( data, 2 );
e = std( data, 1, 2 );
errorbar( y, e, 'xr' );
description = 'Another error bar example.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = legendsubplots()
% size of upper subplot
rows = 4;
% number of points. A large number here (eg 1000) will stress-test
% matlab2tikz and your TeX installation. Be prepared for it to run out of
% memory
length = 100;
% generate some spurious data
t = 0:(4*pi)/length:4*pi;
x = t;
a = t;
y = sin(t) + 0.1*randn(1,length+1);
b = sin(t) + 0.1*randn(1,length+1) + 0.05*cos(2*t);
% plot the top figure
subplot(rows+2,1,1:rows);
% first line
sigma1 = std(y);
tracey = mean(y,1);
plot123 = plot(x,tracey,'b-');
hold on
% second line
sigma2 = std(b);
traceb = mean(b,1);
plot456 = plot(a,traceb,'r-');
spec0 = ['Mean V(t)_A (\sigma \approx ' num2str(sigma1,'%0.4f') ')'];
spec1 = ['Mean V(t)_B (\sigma \approx ' num2str(sigma2,'%0.4f') ')'];
hold off
%plot123(1:2)
legend([plot123; plot456],spec0,spec1)
legend boxoff
xlabel('Time/s')
ylabel('Voltage/V')
title('Time traces');
% now plot a differential trace
subplot(rows+2,1,rows+1:rows+2)
plot7 = plot(a,traceb-tracey,'k');
legend(plot7,'\Delta V(t)')
legend boxoff
xlabel('Time/s')
ylabel('\Delta V')
title('Differential time traces');
description = [ 'Subplots with legends. ' , ...
'Increase value of "length" in the code to stress-test your TeX installation.' ];
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = legendsubplots2()
if isempty(which('tf'))
fprintf( 'function "tf" not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
Rc=1;
C=1.5e-6; %F
% Set inductors
L1=4e-3;
L2=0.8e-3;
% Resistances of inductors
R1=4;
R2=2;
% Transfer functions
% Building transfer functions
s=tf('s');
Zc=1/(s*C)+Rc;
Z1=s*L1+R1;
Z2=s*L2+R2;
LCLd=(Z2+Zc)/(Z1+Zc);
LCL=(s^2*C*L2+1)/(s^2*C*L1+1);
t=logspace(3,5,1000);
hold off
bode(LCL,t)
hold on
bode(LCLd,t)
title('Voltage transfer function of a LCL filter')
set(findall(gcf,'type','line'),'linewidth',1.5)
grid on
legend('Perfect LCL',' Real LCL','Location','SW')
description = ['Another subplot with legends.'];
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = bodeplots()
% check if the control toolbox is installed
if length(ver('control')) ~= 1
fprintf( 'Control toolbox not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
g = tf([1 0.1 7.5],[1 0.12 9 0 0]);
bode(g)
description = 'Bode diagram of frequency response.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = rlocusPlot()
if isempty(which('tf'))
fprintf( 'function "tf" not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
s=tf('s');
rlocus(tf([1 1],[4 3 1]))
description = 'rlocus plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = mandrillImage()
if ~exist('mandrill.mat','file')
fprintf( 'mandrill data set not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
data = load( 'mandrill' );
set( gcf, 'color', 'k' )
image( data.X )
colormap( data.map )
axis off
axis image
description = 'Picture of a mandrill.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = besselImage()
nu = -5:0.25:5;
beta = 0:0.05:2.5;
m = length(beta);
n = length(nu);
trace = zeros(m,n);
for i=1:length(beta);
for j=1:length(nu)
if (floor(nu(j))==nu(j))
trace(i,j)=abs(besselj(nu(j),beta(i)));
end
end
end
imagesc(nu,beta,trace);
colorbar()
xlabel('Order')
ylabel('\beta')
set(gca,'YDir','normal')
description = 'Bessel function.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = clownImage()
if ~exist('clown.mat','file')
fprintf( 'clown data set not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
data = load( 'clown' );
imagesc( data.X )
colormap( gray )
description = 'Picture of a clown.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = zplanePlot1()
% check of the signal processing toolbox is installed
if length(ver('signal')) ~= 1
fprintf( 'Signal toolbox not found. Skip.\n\n' );
description = [];
extraOpts = {};
return
end
[z,p] = ellip(4,3,30,200/500);
zplane(z,p);
title('4th-Order Elliptic Lowpass Digital Filter');
description = 'Representation of the complex plane with zplane.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = zplanePlot2()
% check of the signal processing toolbox is installed
if length(ver('signal')) ~= 1
fprintf( 'Signal toolbox not found. Skip.\n\n' );
description = [];
extraOpts = {};
return
end
[b,a] = ellip(4,3,30,200/500);
Hd = dfilt.df1(b,a);
zplane(Hd) % FIXME: This opens a new figure that doesn't get closed automatically
description = 'Representation of the complex plane with zplane.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = freqResponsePlot()
% check of the signal processing toolbox is installed
if length(ver('signal')) ~= 1
fprintf( 'Signal toolbox not found. Skip.\n\n' );
description = [];
extraOpts = {};
return
end
b = fir1(80,0.5,kaiser(81,8));
hd = dfilt.dffir(b);
freqz(hd); % FIXME: This opens a new figure that doesn't get closed automatically
description = 'Frequency response plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = axesLocation()
plot(rand(1,10));
set(gca,'XAxisLocation','top');
set(gca,'YAxisLocation','right');
description = 'Swapped axis locations.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = axesColors()
plot(rand(1,10));
set(gca,'XColor','g','YColor','b');
% set(gca,'XColor','b','YColor','k');
box off;
description = 'Custom axes colors.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = multipleAxes()
x1 = 0:.1:40;
y1 = 4.*cos(x1)./(x1+2);
x2 = 1:.2:20;
y2 = x2.^2./x2.^3;
line(x1,y1,'Color','r');
ax1 = gca;
set(ax1,'XColor','r','YColor','r')
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
line(x2,y2,'Color','k','Parent',ax2);
xlimits = get(ax1,'XLim');
ylimits = get(ax1,'YLim');
xinc = (xlimits(2)-xlimits(1))/5;
yinc = (ylimits(2)-ylimits(1))/5;
% Now set the tick mark locations.
set(ax1,'XTick',xlimits(1):xinc:xlimits(2) ,...
'YTick',ylimits(1):yinc:ylimits(2) )
description = 'Multiple axes.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = scatterPlotRandom()
n = 1:100;
scatter(n, n, 1000*rand(length(n),1), n.^8);
colormap autumn;
%x = randn( 10, 2 );
%scatter( x(:,1), x(:,2) );
description = 'Generic scatter plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = scatterPlot()
if ~exist('seamount.mat','file')
fprintf( 'seamount data set not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
data = load( 'seamount' );
scatter( data.x, data.y, 5, data.z, '^' );
description = 'Scatter plot with MATLAB(R) data.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = scatterPlotMarkers()
n = 1:10;
d = 10;
s = d^2 * n;
e = d * ones(size(n));
grid on;
hold on;
style = {'bx','rd','go','c.','m+','y*','bs','mv','k^','r<','g>','cp','bh'};
names = {'bx','rd','go','c.','m plus','y star','bs','mv',...
'k up triangle','r left triangle','g right triangle','cp','bh'};
nStyles = numel(style);
for ii = 1:nStyles
scatter(n, ii * e, s, style{ii});
end
xlim([min(n)-1 max(n)+1]);
ylim([0 d*(nStyles+1)]);
set(gca,'XTick',n,'XTickLabel',s,'XTickLabelMode','manual');
legend(names{:});
description = 'Scatter plot with with different marker sizes and legend.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = scatter3Plot()
[x,y,z] = sphere(16);
X = [x(:)*.5 x(:)*.75 x(:)];
Y = [y(:)*.5 y(:)*.75 y(:)];
Z = [z(:)*.5 z(:)*.75 z(:)];
S = repmat([1 .75 .5]*10,numel(x),1);
C = repmat([1 2 3],numel(x),1);
scatter3(X(:),Y(:),Z(:),S(:),C(:),'filled'), view(-60,60)
view(40,35)
description = 'Scatter3 plot with MATLAB(R) data.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = scatter3Plot2()
% Read image (Note: "peppers.png" is available with MATLAB)
InpImg_RGB = imread('peppers.png');
% Subsample image ("scatter3" can't cope with too many points)
InpImg_RGB = InpImg_RGB(1:100:end, 1:100:end, 1:100:end );
InpImg_RGB = reshape(InpImg_RGB, [], 1, 3);
% Split up into single components
r = InpImg_RGB(:,:,1);
g = InpImg_RGB(:,:,2);
b = InpImg_RGB(:,:,3);
% Scatter-plot points
scatter3(r,g,b,15,[r g b]);
xlabel('R');
ylabel('G');
zlabel('B');
description = 'Another Scatter3 plot.';
extraOpts = {};
return
end
% =========================================================================
function [description, extraOpts] = scatter3Plot3()
hold on;
scatter3(rand(5,1),rand(5,1),rand(5,1),150,...
'MarkerEdgeColor','none','MarkerFaceColor','k');
scatter3(rand(5,1),rand(5,1),rand(5,1),150,...
'MarkerEdgeColor','none','MarkerFaceColor','b');
description = 'Scatter3 plot with 2 colors (Issue 292)';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = spherePlot()
sphere(30);
title('a sphere: x^2+y^2+z^2');
xlabel('x');
ylabel('y');
zlabel('z');
axis equal;
description = 'Plot a sphere.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = surfPlot()
[X,Y,Z] = peaks(30);
surf(X,Y,Z)
colormap hsv
axis([-3 3 -3 3 -10 5])
set(gca,'View',[-37.5,36]);
hc = colorbar('YTickLabel', ...
{'Freezing','Cold','Cool','Neutral',...
'Warm','Hot','Burning','Nuclear'});
set(get(hc,'Xlabel'),'String','Multitude');
set(get(hc,'Ylabel'),'String','Magnitude');
set(hc,'YTick',0:0.7:7);
set(hc,'YTickLabel',...
{'-0.8' '-0.6' '-0.4' '-0.2' '0.0' ...
'0.2' '0.4' '0.6' '0.8' '0.10' '0.12'});
set(get(hc,'Title'),...
'String', 'k(u,v)', ...
'FontSize', 12, ...
'interpreter', 'tex');
xlabel( 'x' )
ylabel( 'y' )
zlabel( 'z' )
description = 'Surface plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = surfPlot2()
z = [ ones(15, 5) zeros(15,5); ...
zeros(5,5) zeros(5,5)
];
surf(abs(fftshift(fft2(z))) + 1);
set(gca,'ZScale','log');
legend( 'legendary', 'Location', 'NorthEastOutside' );
description = 'Another surface plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = superkohle()
x1=0;
x2=pi;
y1=0;
y2=pi;
omegashape = [2 2 2 2 % 2 = line segment; 1 = circle segment; 4 = elipse segment
x1 x2 x2 x1 % start point x
x2 x2 x1 x1 % end point x
y1 y1 y2 y2 % start point y
y1 y2 y2 y1 % end point y
1 1 1 1
0 0 0 0];
[xy,edges,tri] = initmesh(omegashape,'Hgrad',1.05);
mmin = 1;
while size(xy,2) < mmin
[xy,edges,tri] = refinemesh(omegashape,xy,edges,tri);
end
m = size(xy,2);
x = xy(1,:)';
y = xy(2,:)';
y0 = cos(x).*cos(y);
pdesurf(xy,tri,y0(:,1));
title('y_0');
xlabel('x1 axis');
ylabel('x2 axis');
axis([0 pi 0 pi -1 1]);
grid on;
description = 'Superkohle plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = meshPlot()
[X,Y,Z] = peaks(30);
mesh(X,Y,Z)
colormap hsv
axis([-3 3 -3 3 -10 5])
xlabel( 'x' )
ylabel( 'y' )
zlabel( 'z' )
description = 'Mesh plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = ylabels()
x = 0:.01:2*pi;
H = plotyy(x,sin(x),x,3*cos(x));
ylabel(H(1),'sin(x)');
ylabel(H(2),'3cos(x)');
xlabel(gca,'time')
description = 'Separate y-labels.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = spectro()
% In the original test case, this is 0:0.001:2, but that takes forever
% for LaTeX to process.
if isempty(which('chirp'))
fprintf( 'chirp() not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
T = 0:0.005:2;
X = chirp(T,100,1,200,'q');
spectrogram(X,128,120,128,1E3);
title('Quadratic Chirp');
description = 'Spectrogram plot';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = mixedBarLine()
x = rand(1000,1)*10;
hist(x,10)
y = ylim;
hold on;
plot([3 3], y, '-r');
hold off;
description = 'Mixed bar/line plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = decayingharmonic()
% Based on an example from
% http://www.mathworks.com/help/techdoc/creating_plots/f0-4741.html#f0-28104
A = 0.25;
alpha = 0.007;
beta = 0.17;
t = 0:901;
y = A * exp(-alpha*t) .* sin(beta*t);
plot(t, y)
title('{\itAe}^{-\alpha\itt}sin\beta{\itt}, \alpha<<\beta')
xlabel('Time \musec.')
ylabel('Amplitude')
description = 'Decaying harmonic oscillation with \TeX{} title.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = texcolor()
% Taken from an example at
% http://www.mathworks.com/help/techdoc/creating_plots/f0-4741.html#f0-28104
text(.1, .5, ['\fontsize{16}black {\color{magenta}magenta '...
'\color[rgb]{0 .5 .5}teal \color{red}red} black again'])
description = 'Multi-colored text using \TeX{} commands.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = textext()
% Taken from an example at
% http://www.mathworks.com/help/techdoc/creating_plots/f0-4741.html#f0-28303
txstr(1) = { 'Each cell is a quoted string' };
txstr(2) = { 'You can specify how the string is aligned' };
txstr(3) = { 'You can use LaTeX symbols like \pi \chi \Xi' };
txstr(4) = { '\bfOr use bold \rm\itor italic font\rm' };
txstr(5) = { '\fontname{courier}Or even change fonts' };
plot( 0:6, sin(0:6) )
text( 5.75, sin(2.5), txstr, 'HorizontalAlignment', 'right' )
description = 'Formatted text and special characters using \TeX{}.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = texrandom()
num = 20; % number of symbols per line
symbols = {'\it', '\bf', '\rm', '\sl', ...
'\alpha', '\angle', '\ast', '\beta', '\gamma', '\delta', ...
'\epsilon', '\zeta', '\eta', '\theta', '\vartheta', ...
'\iota', '\kappa', '\lambda', '\mu', '\nu', '\xi', '\pi', ...
'\rho', '\sigma', '\varsigma', '\tau', '\equiv', '\Im', ...
'\otimes', '\cap', '{\int}', '\rfloor', '\lfloor', '\perp',...
'\wedge', '\rceil', '\vee', '\langle', '\upsilon', '\phi', ...
'\chi', '\psi', '\omega', '\Gamma', '\Delta', '\Theta', ...
'\Lambda', '\Xi', '\Pi', '\Sigma', '\Upsilon', '\Phi', ...
'\Psi', '\Omega', '\forall', '\exists', '\ni', '{\cong}', ...
'\approx', '\Re', '\oplus', '\cup', '\subseteq', '\lceil', ...
'\cdot', '\neg', '\times', '\surd', '\varpi', '\rangle', ...
'\sim', '\leq', '\infty', '\clubsuit', '\diamondsuit', ...
'\heartsuit', '\spadesuit', '\leftrightarrow', ...
'\leftarrow', '\Leftarrow', '\uparrow', '\rightarrow', ...
'\Rightarrow', '\downarrow', '\circ', '\pm', '\geq', ...
'\propto', '\partial', '\bullet', '\div', '\neq', ...
'\aleph', '\wp', '\oslash', '\supseteq', '\nabla', ...
'{\ldots}', '\prime', '\0', '\mid', '\copyright', ...
'\o', '\in', '\subset', '\supset', ...
'\_', '\^', '\{', '\}', '$', '%', '#', ...
'(', ')', '+', '-', '=', '/', ',', '.', '<', '>', ...
'!', '?', ':', ';', '*', '[', ']', 'ยง', '"', '''', ...
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ...
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', ...
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', ...
'w', 'x', 'y', 'z', ...
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', ...
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', ...
'W', 'X', 'Y', 'Z' ...
};
% Note: Instead of '\ldots' the list of symbols contains the entry
% '{\ldots}'. This is because TeX gives an error if it
% encounters the sequence '$a_\ldots$' or '$a^\ldots$'. It
% looks like that is a TeX bug. Nevertheless this sequence
% could appear in the random output, therefore \ldots is
% wrapped in braces since '$a_{\ldots}$' and '$a^{\ldots}$'
% don't crash TeX.
% Same thing with '\cong' and '\int'.
% \color{red} etc. isn't included
% \fontname{Times} etc. isn't included
% \fontsize{12} etc. isn't included
switch getEnvironment()
case 'MATLAB'
% MATLAB expects tilde and ampersand to be un-escaped and backslashes
% to be escaped
symbols = [ symbols, {'~', '&', '\\'} ];
case 'Octave'
% Octave expects tilde and ampersand to be escaped for regular
% output. If either are used un-escaped, that creates odd output in
% Octave itself, but since matlab2tikz should be able to handle
% those cases, let's include the un-escaped symbols in the list.
symbols = [ symbols, {'\~', '\&', '~', '&'} ];
% Octave's backslash handling is weird to say the least. However,
% matlab2tikz treats backslashes the same in Octave as it does in
% MATLAB. Therefore, let's add an escaped backslash to the list
symbols = [ symbols, {'\\'} ];
otherwise
error( 'Unknown environment. Need MATLAB(R) or Octave.' )
end
for ypos = [0.9:-.2:.1]
% Generate `num' random indices to the list of symbols
index = max(ceil(rand(1, num)*length(symbols)), 1);
% Assemble symbols into one cell string array
string = symbols(index);
% Add random amount of balanced braces in random positions to `string'.
% By potentially generating more than one set of braces randomly, it's
% possible to create more complex patterns of nested braces. Increase
% `braceprob' to get more braces, but don't use values greater than or
% equal 1 which would result in an infinite loop.
braceprob = 0.6;
while rand(1,1) < braceprob
% Generate two random numbers ranging from 1 to n with n = number
% of symbols in `string'
bracepos = max(ceil(rand(1, 2)*length(string)), 1);
% Modify `string' so that an opening brace is inserted before
% min(bracepos) symbols and a closing brace after max(bracepos)
% symbols. That way any number of symbols from one to all in
% `string' are wrapped in braces for min(bracepos) == max(bracepos)
% and min(bracepos) == 1 && max(bracepos) == length(string),
% respectively.
string = [string(1:min(bracepos)-1), {'{'}, ...
string(min(bracepos):max(bracepos)), ...
{'}'}, string(max(bracepos)+1:end) ];
end
% Clean up: remove '{}', '{{}}', etc.
clean = false;
while clean == false
clean = true;
for i = 1:length(string)-1
if strcmp( string(i), '{' ) && strcmp( string(i+1), '}' )
string = [string(1:i-1), string(i+2:end)];
clean = false;
break
end
end
end
% Subscripts '_' and superscripts '^' in TeX are tricky in that certain
% combinations are not allowed and there are some subtleties in regard
% to more complicated combinations of sub/superscripts:
% - ^a or _a at the beginning of a TeX math expression is permitted.
% - a^ or a_ at the end of a TeX math expression is not.
% - a__b, a_^b, a^_b, or a^^b is not allowed, as is any number of
% consecutive sub/superscript operators. Actually a^^b does not
% crash TeX, but it produces seemingly random output instead of `b',
% therefore it should be avoided, too.
% - a^b^c or a_b_c is not allowed as it results in a "double subscript/
% superscript" error.
% - a^b_c or a_b^c, however, does work.
% - a^bc^d or a_bc_d also works.
% - a^b_c^d or a_b^c_d is not allowed and results in a "double
% subscript/superscript" error.
% - a{_}b, a{^}b, {a_}b or {a^}b is not permitted.
% - a{_b} or a{^b} is valid TeX code.
% - {a_b}_c produces the same output as a_{bc}. Likewise for '^'.
% - a_{b_c} results in "a index b sub-index c". Likewise for '^'.
% - a^{b}^c or a_{b}_c is not allowed as it results in a "double
% subscript/superscript" error.
%
% From this we can derive a number of rules:
% 1) The last symbol in a TeX string must not be '^' or '_'.
% 2a) There must be at least one non-brace symbol between any '^' and '_'.
% 2b) There must be at least one non-brace symbol between any '_' and '^'.
% 3a) There must either be at least two non-brace, non-'_' symbols or at
% least one non-brace, non-'_' symbol and one brace (opening or
% closing) between any two '^'.
% 3b) There must either be at least two non-brace, non-'^' symbols or at
% least one brace (opening or closing) between any two '_'.
% 4) '^' or '_' must not appear directly before '}'.
% 5) '^' or '_' must not appear directly after '}'.
% 6) Whenever braces were mentioned, that refers to non-empty braces,
% i.e. '{}' counts as nothing. Printable/escaped braces '\{' and '\}'
% also don't count as braces but as regular symbols.
% 7) '^' or '_' must not appear directly before '\it', '\bf', '\rm', or
% '\sl'.
% 8) '^' or '_' must not appear directly after '\it', '\bf', '\rm', or
% '\sl'.
%
% A few test cases:
% Permitted: ^a... _a... a^b_c a_b^c a^bc^d a_bc_d a{_b} a{^b}
% {a_b}_c a_{bc} {a^b}^c a^{bc} a_{b_c} a^{b^c}
% Forbidden: ...z^ ...z_ a__b a_^b a^_b [a^^b] a^b^c a_b_c
% a^b_c^d a_b^c_d a{_}b a{^}b {a_}b {a^}b
% a^{_b} a_{^b} a^{b}^c a_{b}_c
%
% Now add sub/superscripts according to these rules
subsupprob = 0.1; % Probability for insertion of a sub/superscript
caretdist = Inf; % Distance to the last caret
underscdist = Inf; % Distance to the last underscore
bracedist = Inf; % Distance to the last brace (opening or closing)
pos = 0;
% Making sure the post-update `pos' in the while loop is less than the
% number of symbols in `string' enforces rule 1: The last symbol in
% a TeX string must not be '^' or '_'.
while pos+1 < length(string)
% Move one symbol further
pos = pos + 1;
% Enforce rule 7: No sub/superscript directly before '\it', '\bf',
% '\rm', or '\sl'.
if strcmp( string(pos), '\it' ) || strcmp( string(pos), '\bf' ) ...
|| strcmp( string(pos), '\rm' ) || strcmp( string(pos), '\sl' )
continue
end
% Enforce rule 8: No sub/superscript directly after '\it', '\bf',
% '\rm', or '\sl'.
if (pos > 1) ...
&& ( strcmp( string(pos-1), '\it' ) ...
|| strcmp( string(pos-1), '\bf' ) ...
|| strcmp( string(pos-1), '\rm' ) ...
|| strcmp( string(pos-1), '\sl' ) ...
)
continue
end
bracedist = bracedist + 1;
% Enforce rule 4: No sub/superscript directly before '}'
if strcmp( string(pos), '}' )
bracedist = 0; % Also update braces distance
continue
end
% Enforce rule 5: No sub/superscript directly after '}'
if (pos > 1) && strcmp( string(pos-1), '}' )
continue
end
% Update distances for either braces or caret/underscore depending
% on whether the symbol currently under scrutiny is a brace or not.
if strcmp( string(pos), '{' )
bracedist = 0;
else
caretdist = caretdist + 1;
underscdist = underscdist + 1;
end
% Generate two random numbers, then check if any of them is low
% enough, so that with probability `subsupprob' a sub/superscript
% operator is inserted into `string' at the current position. In
% case both random numbers are below the threshold, whether a
% subscript or superscript operator is to be inserted depends on
% which of the two numbers is smaller.
randomnums = rand(1, 2);
if min(randomnums) < subsupprob
if randomnums(1) < randomnums(2)
% Enforce rule 2b: There must be at least one non-brace
% symbol between previous '_' and to-be-inserted '^'.
if underscdist < 1
continue
end
% Enforce rule 3a: There must either be at least two
% non-brace, non-'_' symbols or at least one brace (opening
% or closing) between any two '^'.
if ~( ((caretdist >= 2) && (underscdist >= 2)) ...
|| ((bracedist < 2) && (caretdist >= 2)) )
continue
end
% Insert '^' before `pos'th symbol in `string' now that
% we've made sure all rules are honored.
string = [ string(1:pos-1), {'^'}, string(pos:end) ];
caretdist = 0;
pos = pos + 1;
else
% Enforce rule 2a: There must be at least one non-brace
% symbol between previous '^' and to-be-inserted '_'.
if caretdist < 1
continue
end
% Enforce rule 3b: There must either be at least two
% non-brace, non-'^' symbols or at least one brace (opening
% or closing) between any two '_'.
if ~( ((caretdist >= 2) && (underscdist >= 2)) ...
|| ((bracedist < 2) && (underscdist >= 2)) )
continue
end
% Insert '_' before `pos'th symbol in `string' now that
% we've made sure all rules are honored.
string = [ string(1:pos-1), {'_'}, string(pos:end) ];
underscdist = 0;
pos = pos + 1;
end
end
end % while pos+1 < length(string)
% Now convert the cell string array of symbols into one regular string
string = [string{:}];
% Print the string in the figure to be converted by matlab2tikz
text( .05, ypos, string, 'interpreter', 'tex' )
% And print it to the console, too, in order to enable analysis of
% failed tests
fprintf( 'Original string: %s\n', string )
end
title('Random TeX symbols \\\{\}\_\^$%#&')
description = 'Random TeX symbols';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = latexmath1()
% Adapted from an example at
% http://www.mathworks.com/help/techdoc/ref/text_props.html#Interpreter
axes
title( '\omega\subseteq\Omega' );
text( 0.5, 0.5, '$$\int_0^x\!\int_{\Omega} dF(u,v) d\omega$$', ...
'Interpreter', 'latex', ...
'FontSize', 16 )
description = 'A formula typeset using the \LaTeX{} interpreter.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = latexmath2()
% Adapted from an example at
% http://www.mathworks.com/help/techdoc/creating_plots/f0-4741.html#bq558_t
set(gcf, 'color', 'white')
set(gcf, 'units', 'inches')
set(gcf, 'position', [2 2 4 6.5])
set(gca, 'visible', 'off')
% Note: Most likely due to a bug in matlab2tikz the pgfplots output will
% appear empty even though the LaTeX strings are contained in the
% output file. This is because the following (or something like it)
% is missing from the axis environment properties:
% xmin=0, xmax=4, ymin=-1, ymax=6
% Note: The matrices in h(1) and h(2) cannot be compiled inside pgfplots.
% They are therefore disabled.
% h(1) = text( 'units', 'inch', 'position', [.2 5], ...
% 'fontsize', 14, 'interpreter', 'latex', 'string', ...
% [ '$$\hbox {magic(3) is } \left( {\matrix{ 8 & 1 & 6 \cr' ...
% '3 & 5 & 7 \cr 4 & 9 & 2 } } \right)$$' ]);
% h(2) = text( 'units', 'inch', 'position', [.2 4], ...
% 'fontsize', 14, 'interpreter', 'latex', 'string', ...
% [ '$$\left[ {\matrix{\cos(\phi) & -\sin(\phi) \cr' ...
% '\sin(\phi) & \cos(\phi) \cr}} \right]' ...
% '\left[ \matrix{x \cr y} \right]$$' ]);
h(3) = text( 'units', 'inch', 'position', [.2 3], ...
'fontsize', 14, 'interpreter', 'latex', 'string', ...
[ '$$L\{f(t)\} \equiv F(s) = \int_0^\infty\!\!{e^{-st}' ...
'f(t)dt}$$' ]);
h(4) = text( 'units', 'inch', 'position', [.2 2], ...
'fontsize', 14, 'interpreter', 'latex', 'string', ...
'$$e = \sum_{k=0}^\infty {1 \over {k!} } $$' );
h(5) = text( 'units', 'inch', 'position', [.2 1], ...
'fontsize', 14, 'interpreter', 'latex', 'string', ...
[ '$$m \ddot y = -m g + C_D \cdot {1 \over 2}' ...
'\rho {\dot y}^2 \cdot A$$' ]);
h(6) = text( 'units', 'inch', 'position', [.2 0], ...
'fontsize', 14, 'interpreter', 'latex', 'string', ...
'$$\int_{0}^{\infty} x^2 e^{-x^2} dx = \frac{\sqrt{\pi}}{4}$$' );
% TODO: On processing the matlab2tikz_acidtest output, LaTeX complains
% about the use of \over:
% Package amsmath Warning: Foreign command \over;
% (amsmath) \frac or \genfrac should be used instead
description = 'Some nice-looking formulas typeset using the \LaTeX{} interpreter.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = parameterCurve3d()
ezplot3('sin(t)','cos(t)','t',[0,6*pi]);
text(0.5, 0.5, 10, 'abs');
description = 'Parameter curve in 3D.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = parameterSurf()
if ~exist('TriScatteredInterp')
fprintf( 'TriScatteredInterp() not found. Abort.\n\n' );
description = [];
extraOpts = {};
return;
end
x = rand(100,1)*4 - 2;
y = rand(100,1)*4 - 2;
z = x.*exp(-x.^2 - y.^2);
% Construct the interpolant
% F = TriScatteredInterp(x,y,z,'nearest');
% F = TriScatteredInterp(x,y,z,'natural');
F = TriScatteredInterp(x,y,z,'linear');
% Evaluate the interpolant at the locations (qx, qy), qz
% is the corresponding value at these locations.
ti = -2:.25:2;
[qx,qy] = meshgrid(ti,ti);
qz = F(qx,qy);
hold on
surf(qx,qy,qz)
plot3(x,y,z,'o')
view(gca,[-69 14]);
hold off
description = 'Parameter and surface plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = fill3plot()
if ~exist('fill3','builtin')
fprintf( 'fill3() not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
x1 = -10:0.1:10;
x2 = -10:0.1:10;
p = sin(x1);
d = zeros(1,numel(p));
d(2:2:end) = 1;
h = p.*d;
grid on;
fill3(x1,x2,h,'k');
view(45,22.5);
box on;
description = 'fill3 plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = rectanglePlot()
rectangle('Position', [0.59,0.35,3.75,1.37],...
'Curvature', [0.8,0.4],...
'LineWidth', 2, ...
'LineStyle', '--' ...
);
daspect([1,1,1]);
description = 'Rectangle handle.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = herrorbarPlot()
hold on;
X = 1:10;
Y = 1:10;
err = repmat(0.2, 1, 10);
h1 = errorbar(X, Y, err, 'r');
h_vec = herrorbar(X, Y, err);
for h=h_vec
set(h, 'color', [1 0 0]);
end
h2 = errorbar(X, Y+1, err, 'g');
h_vec = herrorbar(X, Y+1, err);
for h=h_vec
set(h, 'color', [0 1 0]);
end
legend([h1 h2], {'test1', 'test2'})
description = 'herrorbar plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = hist3d()
if ~exist('hist3','builtin') && isempty(which('hist3'))
fprintf( 'Statistics toolbox not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
% load carbig
% X = [MPG,Weight];
% hist3(X,[7 7]);
% xlabel('MPG'); ylabel('Weight');
% set(get(gca,'child'),'FaceColor','interp','CDataMode','auto');
load carbig
X = [MPG,Weight];
hist3(X,[7 7]);
xlabel('MPG'); ylabel('Weight');
hist3(X,[7 7],'FaceAlpha',.65);
xlabel('MPG'); ylabel('Weight');
% Linux crashed with OpenGL.
%%set(gcf,'renderer','opengl');
% load seamount
% dat = [-y,x]; % Grid corrected for negative y-values
% n = hist3(dat); % Extract histogram data;
% % default to 10x10 bins
% view([-37.5, 30]);
description = '3D histogram plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = myBoxplot()
if ~exist('boxplot','builtin') && isempty(which('boxplot'))
fprintf( 'Statistics toolbox not found. Abort.\n\n' );
description = [];
extraOpts = {};
return
end
errors =[
0.810000 3.200000 0.059500
0.762500 -3.200000 0.455500
0.762500 4.000000 0.901000
0.762500 3.600000 0.406000
0.192500 3.600000 0.307000
0.810000 -3.600000 0.604000
1.000000 -2.400000 0.505000
0.430000 -2.400000 0.455500
1.000000 3.200000 0.158500
];
boxplot(errors);
description = 'Boxplot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = areaPlot()
area(1:3, rand(3));
legend('foo', 'bar', 'foobar');
description = 'Area plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = customLegend()
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs');
lh=legend('y',4);
set(lh,'color','g')
set(lh,'edgecolor','r')
set(lh, 'position',[.5 .6 .1 .05])
description = 'Custom legend.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = pixelLegend()
x = linspace(0,1);
plot(x, [x;x.^2]);
set(gca, 'units', 'pixels')
lh=legend('1', '2');
set(lh, 'position', [100 200 65 42])
description = 'Legend with pixel position.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = croppedImage()
if ~exist('flujet.mat','file')
fprintf( 'flujet data set not found. Abort.\n\n' );
description = [];
extraOpts = {};
return;
end
load('flujet','X','map');
image(X)
colormap(map)
%axis off
axis image
xlim([50 200])
ylim([50 200])
% colorbar at top
colorbar('north');
set(gca,'Units','normalized');
description = 'Custom legend.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = doubleAxes()
ah = axes;
set(ah,'Units','pixels');
set(ah,'Position',[18*4 18*3 114*4 114*3]);
ah2 = axes;
set(ah2,'units','pixels')
set(ah2,'position',[18*4 18*3 114*4 114*3])
grid(ah2,'on')
set(ah2,'GridLineStyle','-')
description = 'Double axes.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = pColorPlot()
n = 6;
r = (0:n)'/n;
theta = pi*(-n:n)/n;
X = r*cos(theta);
Y = r*sin(theta);
C = r*cos(2*theta);
pcolor(X,Y,C)
axis equal tight
description = 'pcolor() plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = multiplePatches()
xdata = [2 2 0 2 5;
2 8 2 4 5;
8 8 2 4 8];
ydata = [4 4 4 2 0;
8 4 6 2 2;
4 0 4 0 0];
cdata = [15 0 4 6 10;
1 2 5 7 9;
2 3 0 8 3];
p = patch(xdata,ydata,cdata,'Marker','o',...
'MarkerFaceColor','flat',...
'FaceColor','none');
description = 'Multiple patches.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = hgTransformPlot()
% Check out
% http://www.mathworks.de/de/help/matlab/ref/hgtransform.html.
ax = axes('XLim',[-2 1],'YLim',[-2 1],'ZLim',[-1 1]);
view(3);
grid on;
axis equal;
[x y z] = cylinder([.2 0]);
h(1) = surface(x,y,z,'FaceColor','red');
h(2) = surface(x,y,-z,'FaceColor','green');
h(3) = surface(z,x,y,'FaceColor','blue');
h(4) = surface(-z,x,y,'FaceColor','cyan');
h(5) = surface(y,z,x,'FaceColor','magenta');
h(6) = surface(y,-z,x,'FaceColor','yellow');
t1 = hgtransform('Parent',ax);
t2 = hgtransform('Parent',ax);
set(h,'Parent',t1);
h2 = copyobj(h,t2);
Txy = makehgtform('translate',[-1.5 -1.5 0]);
set(t2,'Matrix',Txy)
drawnow
description = 'hgtransform() plot.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = logbaseline()
bar([0 1 2], [1 1e-2 1e-5],'basevalue', 1e-6);
set(gca,'YScale','log')
description = 'Logplot with modified baseline.';
extraOpts = {};
end
% =========================================================================
function [description, extraOpts] = alphaImage()
N = 20;
h_imsc = imagesc(repmat(1:N, N, 1));
mask = zeros(N);
mask(N/4:3*N/4, N/4:3*N/4) = 1;
set(h_imsc, 'AlphaData', double(~mask));
set(h_imsc, 'AlphaDataMapping', 'scaled');
set(gca, 'ALim', [-1,1]);
description = 'Image with alpha channel.';
extraOpts = {};
end
% =========================================================================
function env = getEnvironment
if ~isempty(ver('MATLAB'))
env = 'MATLAB';
elseif ~isempty(ver('Octave'))
env = 'Octave';
else
env = [];
end
end
% =========================================================================
function [below, noenv] = isVersionBelow ( env, threshMajor, threshMinor )
% get version string for `env' by iterating over all toolboxes
versionData = ver;
versionString = '';
for k = 1:max(size(versionData))
if strcmp( versionData(k).Name, env )
% found it: store and exit the loop
versionString = versionData(k).Version;
break
end
end
if isempty( versionString )
% couldn't find `env'
below = true;
noenv = true;
return
end
majorVer = str2double(regexprep( versionString, '^(\d+)\..*', '$1' ));
minorVer = str2double(regexprep( versionString, '^\d+\.(\d+\.?\d*)[^\d]*.*', '$1' ));
if (majorVer < threshMajor) || (majorVer == threshMajor && minorVer < threshMinor)
% version of `env' is below threshold
below = true;
else
% version of `env' is same as or above threshold
below = false;
end
noenv = false;
end
% =========================================================================
|