\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{pants} \pdfinfo{ /Title (eng-ek125-matlab.pdf) /Creator (Cheatography) /Author (pants) /Subject (ENG EK125 Matlab Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{000000} \definecolor{LightBackground}{HTML}{F7F7F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{ENG EK125 Matlab Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{pants} via \textcolor{DarkBackground}{\uline{cheatography.com/166860/cs/34930/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}pants \\ \uline{cheatography.com/pants} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 26th October, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Basic}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Help}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{doc} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{help} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{demo} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{lookfor} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.06155 cm} x{0.94023 cm} x{1.03122 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{3.833cm}}{\bf\textcolor{white}{Randomizing}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Real Numbers}} & {\bf{Integers}} & {\bf{Seeding}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} rand: range 0-1 & \seqsplit{round(rand*N):} range 0-N & \seqsplit{rng('shuffle'):} sets clock as seed \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} rand*N: range 0-N & randi(n): range 1-n & \seqsplit{rng(intseed):} introduces seed \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{randi*(high-low)+low:} range low-high & randi({[}min,max{]}): range min-max & \seqsplit{rng('default'):} default seed \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Numerical}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Division}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{rem(3,2)=1} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{mod(3,2)=1} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{} \tn % Row Count 3 (+ 0) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{} \tn % Row Count 3 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.81949 cm} x{1.61351 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Arrays}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Creating}} & {\bf{Referring}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} linspace(x,y,n): linear spacing, range x-y, n elem (def n=100) & mat(n): n\textasciicircum{}th\textasciicircum{} element \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} logspace(x,y,n): log spacing, range x-y, n elem (def n=50) & length(vec): total elem in vec \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} rand(n,m): n*m rand matrix & {[}r, c{]}=size(mat): r=rows, c=columns \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} randi({[}min,max{]},n,m): n*m int matrix & length(math): r/c length (biggest) \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} zeros(n,m): n*m matrix of 0 & empty vec: {[} {]} \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} ones(n,m): n*m matrix of 1 & numel(mat): total elem in mat \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.60559 cm} x{1.02687 cm} p{0.34229 cm} p{0.65825 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{3.833cm}}{\bf\textcolor{white}{Misc Matrix}} \tn % Row 0 \SetRowColor{LightBackground} diff & diff between consecutive vec & dot & dot product \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} any & if true for at least 1 elem & cross & cross product \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} all & if true for all elem & diag & returns diag of matrix \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} find & returns indices that meet criteria & trace & sum of elem in diag \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} isequal & compares arrays & eye & n*n identity matrix \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} isdiag & true if diag matrix & \seqsplit{issymmetric} & true if symmetric \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{mean(data},'omitnan') & ommits NaN to calc mean & & \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.26384 cm} p{0.31596 cm} p{0.50027 cm} p{0.55293 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{3.833cm}}{\bf\textcolor{white}{Plotting}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Basic}} & \seqsplit{**Colors} & {\bf{Markers}} & \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `plot(x,y,'r*')`\{\{nl\}\}`axis({[}minx maxx miny maxy{]})` & b: blue & .: point & \textasciicircum{}: up \seqsplit{triangle} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} xlabel, ylabel, title & g: green & o: circle & \textless{}: left \seqsplit{triangle} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} bar, grid, scatter, corrcoef & r: red & x: x & \textgreater{}: right \seqsplit{triangle} \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Lines}} & c: cyan & +: plus & p: \seqsplit{pentagram} \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} -: solid & m: \seqsplit{magenta} & *: star & h: \seqsplit{hexagram} \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} : : dotted & y: \seqsplit{yellow} & s: square & |: \seqsplit{vertical} line \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} -.: dash dot & k: black & d: \seqsplit{diamond} & -: \seqsplit{horizontal} line \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} —: dashed & w: white & v: down \seqsplit{triangle} & \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} `function out = funcname(in)` \{\{nl\}\} `\%define for out` \{\{nl\}\} `end` & Basic user defined function, \% for comments \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `function {[}x,y,z{]} = fnname(a,b)` \{\{nl\}\} `\%print, plot, display` \{\{nl\}\} `end` & Calling with only 1 output var gives 1st value only \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} `function fnname(x,y)` \{\{nl\}\} `\%print, plot, display` \{\{nl\}\} `end` & Input args are not always needed (call `fnname` or `fnname()`) \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} `primary function header` \{\{nl\}\} `body with sub function call` \{\{nl\}\} `end` \{\{nl\}\} `sub function header` \{\{nl\}\} `body` \{\{nl\}\} `end` & Subfunction can only be called by name of the primary \tn % Row Count 19 (+ 7) % Row 4 \SetRowColor{LightBackground} `function outs = pers(x)` \{\{nl\}\} `persistent runsum` \{\{nl\}\} `if isempty(runsum)` \{\{nl\}\} `runsum = 0;` \{\{nl\}\} `end` \{\{nl\}\} `runsum=runsum*x;` \{\{nl\}\} `outsum=runsum;` \{\{nl\}\} `end` & Persistent variables \tn % Row Count 28 (+ 9) % Row 5 \SetRowColor{white} `function out = fnname(x)` \{\{nl\}\} `persistent R` \{\{nl\}\} `if isempty(R)` \{\{nl\}\} `R=0;` \{\{nl\}\} `end` \{\{nl\}\} `out=R+x;` \{\{nl\}\} `R=x;` \{\{nl\}\} `end` & Adds to previous \tn % Row Count 36 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Functions (cont)}} \tn % Row 6 \SetRowColor{LightBackground} `function {[}x,y{]} = coor(theta)` \{\{nl\}\} `x=1;` \{\{nl\}\} `y=2;` \{\{nl\}\} `end` & Function stub \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.0299 cm} x{2.4031 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Matrix Manipulation}} \tn % Row 0 \SetRowColor{LightBackground} reshape(mat,n,m) & re-dimensions columnwise \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} fliplr & flips matrix left to right \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} flipud & flips matrix upside down \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} rot90 & rotates matrix counterclockwise 90° \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} repmat(mat,n,m) & replicates n*m copies of mat \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} repelem(mat,n,m) & replicates elements from mat n*m times \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{cumsum/cumprod} & cumulative sum/product \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} min(vec) & minimum vector value \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} max(vec) & maximum vector value \tn % Row Count 14 (+ 1) % Row 9 \SetRowColor{white} sum(vec) & sum vector elements \tn % Row Count 15 (+ 1) % Row 10 \SetRowColor{LightBackground} prod(vec) & product vector elements \tn % Row Count 16 (+ 1) % Row 11 \SetRowColor{white} abs(vec) & absolute vector values \tn % Row Count 17 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}