{"id":108,"date":"2007-09-19T10:18:40","date_gmt":"2007-09-19T15:18:40","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/2007\/09\/19\/numbered-argument-specification\/"},"modified":"2016-08-02T13:05:29","modified_gmt":"2016-08-02T18:05:29","slug":"numbered-argument-specification","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2007\/09\/19\/numbered-argument-specification\/","title":{"rendered":"Numbered Argument Specification for Print Functions"},"content":{"rendered":"<div class=\"content\">\n<p>Since MATLAB Release R2007a, you've been able to number the arguments for functions that format strings. With this feature,<br \/>\nyou can refer to the values that correspond to the different arguments in a varying order. So what mischief can we get up<br \/>\nto?<\/p>\n<p>&nbsp;<\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#1\">Possible Uses<\/a><\/li>\n<li><a href=\"#3\">References<\/a><\/li>\n<li><a href=\"#4\">Other Uses?<\/a><\/li>\n<\/ul>\n<\/div>\n<h3>Possible Uses<a name=\"1\"><\/a><\/h3>\n<p>There are at least two cases I can think of where being able to refer to specific arguments by position can be useful.<\/p>\n<div>\n<ul>\n<li>Translation<\/li>\n<\/ul>\n<\/div>\n<p>This can be important to users writing code for broad use, where some of the output might need to be written in different<br \/>\nlanguages or the language the output is written in depends on the locale. Not all languages express certain ideas in the same<br \/>\nway, and this may necessitate using the arguments in a different order depending on the output language (sort of like <a href=\"http:\/\/www.google.com\/url?sa=t&amp;ct=res&amp;cd=2&amp;url=http%3A%2F%2Fwww.vinc17.org%2Fyp17%2Findex.fr.html&amp;ei=hVbpRubYCZi8epOv7NMG&amp;usg=AFQjCNFugfbYyh05xFTNUfZp7o4w1ayYrQ&amp;sig2=IX3SnOTalBaKDWdKWCazPA\">cochon jaune<\/a> in French vs. yellow pig in English).<\/p>\n<div>\n<ul>\n<li>Argument reuse<\/li>\n<\/ul>\n<\/div>\n<p>There are cases in which you might want to reuse an argument when writing out a string (perhaps a string of code or html).<br \/>\nHere's a case where we want to have a string and its value match each other; the radio button label is the actual value.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">optionName = <span style=\"color: #a020f0;\">'Case'<\/span>;\r\noptionValue = <span style=\"color: #a020f0;\">'Ignore'<\/span>;\r\ns = sprintf(<span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'&lt;input type=radio name=\"%1$s\" value=\"%2$s\"\/&gt;%2$s\\n'<\/span>, <span style=\"color: #0000ff;\">...<\/span>\r\n    optionName, optionValue)<\/pre>\n<pre style=\"font-style: oblique;\">s =\r\n&lt;input type=radio name=\"Case\" value=\"Ignore\"\/&gt;Ignore\r\n\r\n<\/pre>\n<h3>References<a name=\"3\"><\/a><\/h3>\n<p>Here are some MATLAB references for formatting strings.<\/p>\n<div>\n<ul>\n<li>Documentation for Formatting Strings - Note especially the section on restrictions for using the ordered identifiers.<\/li>\n<li>R2007a Release Notes<\/li>\n<li>See the <a href=\"https:\/\/www.mathworks.com\/support\/functions\/alpha_list.html\">help<\/a> for these related functions: <tt>sprintf<\/tt>, <tt>fprintf<\/tt>, <tt>error<\/tt>, <tt>warning<\/tt>, <tt>assert<\/tt><\/li>\n<\/ul>\n<\/div>\n<h3>Other Uses?<a name=\"4\"><\/a><\/h3>\n<p>Can you think of cases where you would take advantage of this? Post them <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=108#respond\">here<\/a> so we can see them!<\/p>\n<p><script>\/\/ <![CDATA[\nfunction grabCode_709b0a20ad3244a2a97c9f3955998c3d() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='709b0a20ad3244a2a97c9f3955998c3d ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 709b0a20ad3244a2a97c9f3955998c3d';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Loren Shure';\n        copyright = 'Copyright 2007 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n\n\n\n\n<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\n\n\n\n\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }\n\/\/ ]]><\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\"><a><span style=\"font-size: x-small; font-style: italic;\">Get<br \/>\nthe MATLAB code<br \/>\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>Published with MATLAB\u00ae 7.5<\/p>\n<\/div>\n<p><!--\n709b0a20ad3244a2a97c9f3955998c3d ##### SOURCE BEGIN #####\n%% Numbered Argument Specification for Print Functions\n% Since MATLAB Release R2007a, you've been able to number the arguments for\n% functions that format strings.  With this feature, you can refer to the\n% values that correspond to the different arguments in a varying order.  So\n% what mischief can we get up to?\n%% Possible Uses\n% There are at least two cases I can think of where being able to refer to\n% specific arguments by position can be useful.\n%\n% * Translation\n%\n% This can be important to users writing code for broad use,\n% where some of the output might need to be written in different languages\n% or the language the output is written in depends on the locale.\n% Not all languages express certain ideas in the same way, and this may\n% necessitate using the arguments in a different order depending on the\n% output language (sort of like\n% <http:\/\/www.google.com\/url?sa=t&ct=res&cd=2&url=http%3A%2F%2Fwww.vinc17.org%2Fyp17%2Findex.fr.html&ei=hVbpRubYCZi8epOv7NMG&usg=AFQjCNFugfbYyh05xFTNUfZp7o4w1ayYrQ&sig2=IX3SnOTalBaKDWdKWCazPA cochon jaune>\n% in French vs. yellow pig in English).\n%%\n%\n% * Argument reuse\n%\n% There are cases in which you might want to reuse an\n% argument when writing out a string (perhaps a string of code or html).\n% Here's a case where we want to have a string and its value match each\n% other; the radio button label is the actual value.\n%\noptionName = 'Case';\noptionValue = 'Ignore';\ns = sprintf(...\n'<input type=radio name=\"%1$s\" value=\"%2$s\"\/>%2$s\\n', ...\noptionName, optionValue)\n%% References\n% Here are some MATLAB references for formatting strings.\n%\n% * Documentation for <https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/matlab_prog\/f2-47856.html#bq0he44-1 Formatting Strings>\n%  - Note especially the section on restrictions for using the ordered\n% identifiers.\n% * R2007a <https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/rn\/bq08o1n-1.html#bq24lnj-1 Release Notes>\n% * See the <https:\/\/www.mathworks.com\/support\/functions\/alpha_list.html help>\n% for these related functions: |sprintf|, |fprintf|, |error|, |warning|,\n% |assert|\n%\n%% Other Uses?\n% Can you think of cases where you would take advantage of this?  Post them\n% <https:\/\/blogs.mathworks.com\/loren\/?p=108#respond here> so we can see\n% them!\n\n##### SOURCE END ##### 709b0a20ad3244a2a97c9f3955998c3d\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\nSince MATLAB Release R2007a, you've been able to number the arguments for functions that format strings. With this feature,<br \/>\nyou can refer to the values that correspond to the different arguments in... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2007\/09\/19\/numbered-argument-specification\/\">read more >><\/a><\/p>\n","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,6],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/108"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":1885,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/108\/revisions\/1885"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}