{"id":476,"date":"2017-05-15T19:43:08","date_gmt":"2017-05-16T03:43:08","guid":{"rendered":"http:\/\/wonghoi.humgar.com\/blog\/?page_id=476"},"modified":"2017-05-15T19:43:08","modified_gmt":"2017-05-16T03:43:08","slug":"matlab-the-know-it-cold-list","status":"publish","type":"page","link":"https:\/\/wonghoi.humgar.com\/blog\/matlab-the-know-it-cold-list\/","title":{"rendered":"MATLAB: The &#8220;know it cold&#8221; list"},"content":{"rendered":"<p>Very often, the MATLAB documentation is enough\u00a0for anybody with a vague idea of what they want to dig their way to the right concepts\/features to solve their problem. Nonetheless, there are few handy tools or quirks that\u00a0are &#8220;either you know it or you don&#8217;t&#8221;.<\/p>\n<p>Most of the tips in the following list are essential to avoid super-clumsy maneuvers. I&#8217;ve seen enough people that developed messy workarounds just because they didn&#8217;t know these:<\/p>\n<ul>\n<li>addpath( genpath() ): now you can organize your code by folder and add it in one shot!\u00a0Preach it!<br \/>\naddpath(&#8230;, &#8216;-end&#8217;):\u00a0gives the new paths lower priority to avoid shadowing existing functions<\/li>\n<li>userpath(&#8216;reset&#8217;): fixes it when\u00a0you see MATLAB starting in &#8220;C:\\Windows\\System32&#8221;.\u00a0\n<\/li>\n<li>verLessThan(): deal with backward compatibility issues<\/li>\n<li>struct2table(ver()) instead of plain ver(), which gives you a nasty array of structs<br \/>\nstruct2table(dir()) instead of plain dir(), which gives you a nasty array of structs<\/p>\n<\/li>\n<li>spotting implicit run-length encoding<\/li>\n<li>spotting implicit uses of diff()\/cumsum(). <br \/>\ndiff() is easy to come up with, but we often missed cumsum().<\/li>\n<li>comma separated list from dereferencing multiple cells (e..g C{:}) or multiple array-of-structs.<\/li>\n<li>[varargout{1:nargout}] = f(&#8230;)<\/li>\n<li>relay varargin by varargin{:}<\/li>\n<li>use\u00a0exist(&#8230;, &#8216;var&#8217;) to define simple optional arguments instead of counting argument numbers (nargin). <\/li>\n<\/ul>\n<p>I&#8217;ll expand the list as I recall more concepts. Keep checking this page for updates. Feel free to suggest more in the comments section<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_476\" class=\"pvc_stats all  \" data-element-id=\"476\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Very often, the MATLAB documentation is enough\u00a0for anybody with a vague idea of what they want to dig their way to the right concepts\/features to solve their problem. Nonetheless, there are few handy tools or quirks that\u00a0are &#8220;either you know &hellip; <a href=\"https:\/\/wonghoi.humgar.com\/blog\/matlab-the-know-it-cold-list\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_476\" class=\"pvc_stats all  \" data-element-id=\"476\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-476","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/pages\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/comments?post=476"}],"version-history":[{"count":1,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/pages\/476\/revisions"}],"predecessor-version":[{"id":477,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/pages\/476\/revisions\/477"}],"wp:attachment":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/media?parent=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}