{"id":317,"date":"2009-06-15T11:24:34","date_gmt":"2009-06-15T11:24:34","guid":{"rendered":"https:\/\/blogs.mathworks.com\/desktop\/2009\/06\/15\/fold-whatever-you-want-using-cells\/"},"modified":"2009-06-15T11:24:34","modified_gmt":"2009-06-15T11:24:34","slug":"fold-whatever-you-want-using-cells","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2009\/06\/15\/fold-whatever-you-want-using-cells\/","title":{"rendered":"Fold whatever you want using cells"},"content":{"rendered":"<p><a href=\"https:\/\/blogs.mathworks.com\/community\/2008\/04\/28\/code-folding-update-in-r2008a\/#comment-6279\">Juliette recently suggested<\/a> that users should be able to fold whatever code they like. While this is a great feature idea, the MATLAB Editor doesn&#8217;t currently support folding arbitrary sections of code. You can, however, simulate the feature using cells.<\/p>\n<p>Start by turing on Cell folding in <b>Preferences -> Editor\/Debugger -> Code Folding<\/b> (folding cells is off by default). Now, take your raw code, which we&#8217;ll say looks like this:<\/p>\n<div align=\"left\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/ken_orr_folding_with_cells\/code.png\">\n<\/div>\n<p><\/p>\n<p>and insert cell markers before and after the code you want to fold, like this:<\/p>\n<div align=\"left\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/ken_orr_folding_with_cells\/code_with_unfolded_cells.png\">\n<\/div>\n<p><\/p>\n<p>Finally, collapse the cell and voila! You&#8217;ve folded an arbitrary chunk of code!<\/p>\n<div align=\"left\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/ken_orr_folding_with_cells\/code_with_folded_cells.png\">\n<\/div>\n<p><\/p>\n<p>I realize this isn&#8217;t the ideal solution for folding a random chunk of code, but it&#8217;s a reasonable workaround in the meantime.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Juliette recently suggested that users should be able to fold whatever code they like. While this is a great feature idea, the MATLAB Editor doesn&#8217;t currently support folding arbitrary sections&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2009\/06\/15\/fold-whatever-you-want-using-cells\/\">read more >><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/317"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}