\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{{[}deleted{]}} \pdfinfo{ /Title (matlab-repo.pdf) /Creator (Cheatography) /Author ({[}deleted{]}) /Subject (MATLAB Repo 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}{1B58C2} \definecolor{LightBackground}{HTML}{F0F4FB} \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{MATLAB Repo Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{{[}deleted{]}} via \textcolor{DarkBackground}{\uline{cheatography.com/52740/cs/14288/}}} \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}{[}deleted{]} \\ \uline{cheatography.com/deleted-52740} \\ \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 18th January, 2018.\\ 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*}{2} \begin{tabularx}{8.4cm}{x{4.48 cm} x{3.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Naming conventions}} \tn % Row 0 \SetRowColor{LightBackground} Variable names in camel case & `moveToPosition` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Functions \& methods in camel case & \seqsplit{`sendFilesOverNetwork`} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Acronyms follow camel case & `htmlPage, isJpeg` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Use meaningful names & `wage = hourlyRate * nHours` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\emph{n}} prefix for amounts & `nFiles` \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} {\emph{No}} suffix for specific numbers & `measurementNo` \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} {\emph{Cnt}} suffix for iterator variables & `sampleCnt = 1:nSamples` \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} Constant uppercase + underscore & `SPEED\_OF\_LIGHT` \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} Classes \& stuctures capitalized & `RadarSensor` \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} Non-default units in variable name & \seqsplit{`BOTTLE\_CAPACITY\_CL} = 50` \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Layout}} \tn % Row 0 \SetRowColor{LightBackground} Split lines if needed & `longMethodName(... \{\{nl\}\} long, list, of, params)` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Align for better readability & `value = (10 * nDimes) + ... \{\{nl\}\}~~~~~~~~(5~~* nNickels) + ... \{\{nl\}\}~~~~~~~~(1~~* nPennies);` \tn % Row Count 13 (+ 10) % Row 2 \SetRowColor{LightBackground} Commas are followed by spaces & `add(a, b, c)` \tn % Row Count 15 (+ 2) % Row 3 \SetRowColor{white} Brackets are NOT surrounded by spaces & \seqsplit{`mean(profitPerMonth)`} \tn % Row Count 17 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Separate logical groups of code by a blank line} \tn % Row Count 18 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Separate functional groups of code by using `\%\%`} \tn % Row Count 19 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Page break 1}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Best practices}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Write code as functions when possible} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}The main role of scripts is in development because they provide direct visibility of variables. Functions modularize computation by using internal variables, and tend to be cleaner and more flexible. It is also much easier to manage changes if code appears in only one file.} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Don't (always) use `clear all`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Whenever Matlab meets new code it pre-compiles it, making re-runs faster. Make sure you don't use `clear all` when you meant to use `clear` - the former not only clears variables but also the pre-compiled code.} \tn % Row Count 13 (+ 6) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Helper functions} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}A single .m file can contain multiple functions. Although only the first function is exposed, this allows for better structuring and reuse of the code.} \tn % Row Count 18 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Subfunctions} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}It's possible to nest functions, allowing for better structuring while strongly associating the subfunction with it parent.} \tn % Row Count 22 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comments}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Write comments only when needed} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} For comments after code, prefix '␣␣\%␣' & `SAMPLE\_FREQ = 3e9~~\%~Hz` \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} Align for better readability & `var = 1;~~~~~~~\%~Comment \{\{nl\}\}otherVar = 2;~~\%~Other comment` \tn % Row Count 10 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Documentation}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Class header gives a description of the class and a summary of all its functions} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Function headers give information about the inputs \& outputs} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Include a demo file for non-trivial classes and functions} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Speed-ups}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Preallocation} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Allocate empty matrices to store incremental results generated by loops. If the number of results is unknown, you can allocate the for maximum amount and prune afterward (if possible).} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Vectorization} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Placing a period (.) before the operators *, /, and \textasciicircum{}, transforms them into array operators.\{\{nl\}\} Some functions also accept vectors/matrices as input and perform their computations on element/row-wise. \{\{nl\}\}\{\{nl\}\} {\emph{Example}}\{\{nl\}\} ` t = 0:.01:10;\{\{nl\}\} y = sin(t); `} \tn % Row Count 12 (+ 7) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Indexing} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Use vector or boolean indexing instead of loops where possible\{\{nl\}\}\{\{nl\}\} {\emph{Example}}\{\{nl\}\} ` someNumbers(someNumbers \textless{} 0) = 0; `} \tn % Row Count 16 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Profiler} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}To determine which parts of your code are the most time consuming use the `tic toc`, `timeit`, or `profile` commands.} \tn % Row Count 20 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Workflow}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Create a new branch for your feature} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`git checkout -b {\emph{featurename}}`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Use git as you normally would} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`git add {\emph{file1.m}} {\emph{file2.m}}`\{\{nl\}\}`git commit -m "{\emph{message}}"`\{\{nl\}\}`git pull origin {\emph{featurename}}`\{\{nl\}\}`git push origin {\emph{featurename}}`} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Regularly merge the master branch into the feature branch} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`(git checkout {\emph{featurename}})`\{\{nl\}\}`git fetch origin` \{\{nl\}\} `git merge origin/master`} \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{One the feature is completed, file a merge request on GitLab.} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}If your request if rejected.} \tn % Row Count 13 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Sources}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Guidelines for writing clean and fast code in MATLAB - Nico Schl{\"o}mer} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{MATLAB Style Guidelines 2.0 - Richard Johnson} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The Elements of MATLAB Style - Richard Johnson} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}