{"id":2526,"date":"2010-01-29T15:04:44","date_gmt":"2010-01-29T15:04:44","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/29\/patching-together-a-bmw-z4\/"},"modified":"2010-01-29T16:15:37","modified_gmt":"2010-01-29T16:15:37","slug":"patching-together-a-bmw-z4","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/29\/patching-together-a-bmw-z4\/","title":{"rendered":"Patching together a BMW Z4"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction><\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">One From the Gallery<\/a><\/li>\r\n         <li><a href=\"#8\">Some Notes<\/a><\/li>\r\n         <li><a href=\"#9\">\"Virtual Career Fair\"<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>One From the Gallery<a name=\"1\"><\/a><\/h3>\r\n   <p>This week's Pick is of the Week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/7856-car\">Car<\/a>, by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/18773\">Ronald Biro<\/a>.\r\n   <\/p>\r\n   <p>Ronald's file creates a graphical reconstruction of a BMW Roadster, and gets me as close to this sweet ride as I am likely\r\n      to get in the near future.\r\n   <\/p>\r\n   <p>Ronald created his version of the Z4, shown here<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"\r\nhttps:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/patchcarfit.png\"> <\/p>\r\n   <p>using nearly 200 calls to his own version of \"patches\". Actually, Ronald's <tt>mypatch<\/tt> calls to and creates low-level <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/surface.html\"><tt>surface<\/tt><\/a> objects. I'd be interested to hear the author's rationale for using surface objects instead of true patches. (For a brief\r\n      discussion of the differences, read <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/visualize\/f2-31825.html#f2-17145\">this<\/a>.)\r\n   <\/p>\r\n   <p>Just for comparison, here's the real deal:<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/realcarfit.png\"> <\/p>\r\n   <h3>Some Notes<a name=\"8\"><\/a><\/h3>\r\n   <p>When I first ran the Z4.m file, it executed perfectly on my computer. On the other hand, Bob quickly got an error running\r\n      the same file on his computer. Why the difference? I like to <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/warning.html\">disable warnings<\/a> in my <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/startup.html\">startup file<\/a>, so the offending issue was ignored when I ran the code. In this case, had I enabled my warnings (their default state), MATLAB\r\n      would have warned me me that \"the variable \"Z4\" is also the name of this script.\" That can be problematic because MATLAB won't\r\n      be able to differentiate the script from the variable in any context from which the script is called. (So, readers, be aware\r\n      that you may need to suppress your warnings to run the file.)\r\n   <\/p>\r\n   <p>One more thing: the integration of the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_env\/brqxeeu-151.html \">M-Lint Code Analyzer<\/a>\r\ninto the MATLAB Editor is really helpful for identifying code issues. There are several places in which (more size-appropriate) <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_prog\/f8-784135.html#f8-793781\">preallocations<\/a> might improve the performance of the code (admittedly, less of an issue in a just-for-fun gallery submission), and other\r\n      places where <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_prog\/f0-41244.html#f0-45379\">command window output could be suppressed<\/a> with a simple semicolon. Still, I like the file; a lot of work clearly went into it, and it is of limited practical use.\r\n      My wife might say the same of me. :)\r\n   <\/p>\r\n   <h3>\"Virtual Career Fair\"<a name=\"9\"><\/a><\/h3>\r\n   <p>Also, before I sign off, one bit of promotion: The MathWorks will be holding a \"Virtual Career Fair\" from 11 a.m. to 7 p.m.\r\n      on February 4, 2010. This Fair is designed to give graduate students and recent grads an opportunity to learn more about careers\r\n      at The MathWorks, and to chat live with engineers and managers about the company. Interested? Register <a href=\"http:\/\/www.accessinteractive.com\/cgi-bin\/mathworks_agency_profile?enc=6E303D32353635266E393D5669727475616C20436172656572204661697220322D32303130266E31303D50726F66657373696F6E616C204576656E74266E31313D5669727475616C20436172656572204661697220322D32303130266E31373D333233333335333336413636373236313645364236433639266E31383D6D69736331266E32303D54696D2E4576616E73406D617468776F726B732E636F6D266E32373D37363033266E32383D726561646F6E6C79266E32393D5669727475616C204361726565722046616972205369676E7570266E39393D5553266E3130303D\">here.<\/a><\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2526#respond\">Comments?<\/a><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_30b203e334f54cf0b4cfe06dbe6ee564() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='30b203e334f54cf0b4cfe06dbe6ee564 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 30b203e334f54cf0b4cfe06dbe6ee564';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Brett Shoelson';\r\n        copyright = 'Copyright 2010 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_30b203e334f54cf0b4cfe06dbe6ee564()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\n30b203e334f54cf0b4cfe06dbe6ee564 ##### SOURCE BEGIN #####\r\n%% Patching together a BMW Z4\r\n%% One From the Gallery\r\n% This week's Pick is of the Week is <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/7856-car \"car\">,\r\n% by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/18773 Ronald Biro>.\r\n\r\n%%\r\n% Ronald's file creates a graphical reconstruction of a BMW Roadster, and gets me as\r\n% close to this sweet ride as I am likely to get in the near future.\r\n\r\n%% \r\n% Ronald created his version of the Z4, shown here:\r\n\r\n%%\r\n% \r\n% <<PatchCar.png>>\r\n% \r\n\r\n%%\r\n% using nearly 200 calls to his own version of \"patches\". Actually, Ronald's |mypatch| call and creates low-level \r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/surface.html |surface|> objects. I'd be interested to\r\n% hear the author's rationale for using surface objects instead of true patches. (For a brief discussion of the\r\n% differences, read <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/visualize\/f2-31825.html#f2-17145 this>.)\r\n\r\n%%\r\n% Just for comparison, here's the real deal:\r\n\r\n%%\r\n% \r\n% <<RealCar.png>>\r\n%\r\n\r\n%% Some Notes\r\n% When I first ran the Z4.m file, it executed perfectly on my computer. On the other hand, Bob\r\n% quickly got an error running the same file on his computer. Why the\r\n% difference? I like to <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/warning.html disable warnings> in my\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/startup.html startup file>, \r\n% so the offending issue was ignored when I ran the code. In this case, had\r\n% I enabled my warnings (their default state), MATLAB would have warned me me that \"the variable \"Z4\" is also the name of this\r\n% script.\" That can be problematic because MATLAB won't be able to\r\n% differentiate the script from the variable in any context from which the\r\n% script is called. (So, readers, be aware that you may need to suppress\r\n% your warnings to run the file.)\r\n%\r\n% One more thing: the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/mlint.html MLINT Editor> is really helpful \r\n% for identifying code issues. There are several places in which (more\r\n% size-appropriate)\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_prog\/f8-784135.html#f8-793781 preallocations> might improve the performance of the code (admittedly, less of an\r\n% issue in a just-for-fun gallery submission), and other places where\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_prog\/f0-41244.html#f0-45379 command window output could be suppressed> with a simple\r\n% semicolon. Still, I like the file; a lot of work clearly went into it, and it is of limited practical use. My wife might say the same of me. :) \r\n\r\n%% \"Virtual Career Fair\"\r\n% Also, before I sign off, one bit of promotion: The MathWorks will be\r\n% holding a \"Virtual Career Fair\" from 11 a.m. to 7 p.m. on February 4,\r\n% 2010. This Fair is designed to give graduate students and recent grads an\r\n% opportunity to learn more about careers at The MathWorks, and to chat\r\n% live with engineers and managers about the company. Interested? Register\r\n% <http:\/\/www.accessinteractive.com\/cgi-bin\/mathworks_agency_profile?enc=6E303D32353635266E393D5669727475616C20436172656572204661697220322D32303130266E31303D50726F66657373696F6E616C204576656E74266E31313D5669727475616C20436172656572204661697220322D32303130266E31373D333233333335333336413636373236313645364236433639266E31383D6D69736331266E32303D54696D2E4576616E73406D617468776F726B732E636F6D266E32373D37363033266E32383D726561646F6E6C79266E32393D5669727475616C204361726565722046616972205369676E7570266E39393D5553266E3130303D here.>\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2526#respond Comments?>\r\n##### SOURCE END ##### 30b203e334f54cf0b4cfe06dbe6ee564\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n   Contents\r\n   \r\n      \r\n         One From the Gallery\r\n         Some Notes\r\n         \"Virtual Career Fair\"\r\n... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/29\/patching-together-a-bmw-z4\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2526"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2526"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2526\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}