{"id":2949,"date":"2010-10-15T17:07:29","date_gmt":"2010-10-15T16:07:29","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=2949"},"modified":"2010-10-15T17:07:29","modified_gmt":"2010-10-15T16:07:29","slug":"has-matlab-lost-its-sense-of-humour","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=2949","title":{"rendered":"Has MATLAB lost its sense of humour?"},"content":{"rendered":"<p>MATLAB has a command called reshape that,obviously enough, allows you to reshape a matrix.<\/p>\n<pre>\r\nmat=rand(4)\r\nmat =\r\n    0.1576    0.8003    0.7922    0.8491\r\n    0.9706    0.1419    0.9595    0.9340\r\n    0.9572    0.4218    0.6557    0.6787\r\n    0.4854    0.9157    0.0357    0.7577\r\n\r\n&gt;&gt; reshape(mat,[2,8])\r\nans =\r\n    0.1576    0.9572    0.8003    0.4218    0.7922    0.6557    0.8491    0.6787\r\n    0.9706    0.4854    0.1419    0.9157    0.9595    0.0357    0.9340    0.7577\r\n<\/pre>\n<p>Obviously, the number of rows and columns both have to be positive.  A negative number of rows and columns makes no sense at all.  On MATLAB 2010a:<\/p>\n<pre>\r\n>> reshape(mat,[-2,-8])\r\n??? Error using ==> reshape\r\nSize vector elements should be nonnegative.\r\n<\/pre>\n<p>So far so boring.  However, I found an old copy of MATLAB on my system (version 6.5.1) which gives much more interesting error messages<\/p>\n<pre>\r\n>> reshape(mat,[-2,-8])\r\n??? Error using ==> reshape\r\nDon't do this again!.\r\n<\/pre>\n<p>Obviously, I ignore the warning<\/p>\n<pre>\r\n>> reshape(mat,[-2,-8])\r\n??? Error using ==> reshape\r\nCleve says you should be doing something more useful.\r\n<\/pre>\n<p>Nope, I&#8217;ve got nothing better to do<\/p>\n<pre>\r\n??? Error using ==> reshape\r\nSeriously, size arguments cannot be negative.\r\n<\/pre>\n<p>I don&#8217;t know about you but I prefer the old error messages myself.  MATLAB hasn&#8217;t completely lost its sense of humour, however, try evaluating the following for example<\/p>\n<pre>\r\nspy\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MATLAB has a command called reshape that,obviously enough, allows you to reshape a matrix. mat=rand(4) mat = 0.1576 0.8003 0.7922 0.8491 0.9706 0.1419 0.9595 0.9340 0.9572 0.4218 0.6557 0.6787 0.4854 0.9157 0.0357 0.7577 &gt;&gt; reshape(mat,[2,8]) ans = 0.1576 0.9572 0.8003 0.4218 0.7922 0.6557 0.8491 0.6787 0.9706 0.4854 0.1419 0.9157 0.9595 0.0357 0.9340 0.7577 Obviously, the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[45,4,11],"tags":[],"class_list":["post-2949","post","type-post","status-publish","format-standard","hentry","category-just-for-fun","category-math-software","category-matlab"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-Lz","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2949"}],"version-history":[{"count":5,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2949\/revisions"}],"predecessor-version":[{"id":2954,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2949\/revisions\/2954"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}