{"id":360,"date":"2010-01-25T15:38:52","date_gmt":"2010-01-25T15:38:52","guid":{"rendered":"https:\/\/blogs.mathworks.com\/desktop\/2010\/01\/25\/open-as-text\/"},"modified":"2010-01-25T16:55:48","modified_gmt":"2010-01-25T16:55:48","slug":"open-as-text","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2010\/01\/25\/open-as-text\/","title":{"rendered":"Open as Text"},"content":{"rendered":"<p>I bet good odds that most of our users don&#8217;t know about the &#8220;Open As Text&#8221; feature in the Current Folder Browser. Double-clicking on files in the Current Folder will try to open the file using MATLAB&#8217;s implementation of the <tt>open<\/tt> function. That means importing to the workspace for a data file, loading of a mdl-file in Simulink, and editing a regular &#8220;.m&#8217; file in the Editor. Sometimes we may not want to open the file in the default way, but instead want to look at or edit the file as if it were a plain text file. <\/p>\n<p>Let&#8217;s say I wanted to compare the years the Yankees and Red Sox won the World Series. To do this, I&#8217;ll have my friend over in the facts department sent me a tab-delimited file with the years each team won the World Series, &#8220;ws.dat&#8221;. Double-clicking it in the Current Folder Browser does the same operation as the MATLAB command <tt>open('ws.dat')<\/tt>, that is, the <a href=\"https:\/\/blogs.mathworks.com\/community\/2008\/08\/18\/its-all-about-the-data\/\">Import Wizard<\/a> is launched and the data can be imported into the workspace. <\/p>\n<div align=\"center\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/michael_katz_open_as_text\/import_ws.png\" alt=\"Double-click to import\">\n<\/div>\n<p>With this imported data, we can quickly visualize the years that each team won the World Series (I&#8217;ll leave it as an exercise for the the reader to interpret the results). <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">cla\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nbar(data(:,2),repmat(1,1,27),<span style=\"color: #A020F0\">'r'<\/span>)\r\nbar(data(:,1),repmat(1,1,27),<span style=\"color: #A020F0\">'b'<\/span>)\r\nset(gca,<span style=\"color: #A020F0\">'YTickLabel'<\/span>,[])\r\nset(gca,<span style=\"color: #A020F0\">'YTick'<\/span>,[])\r\nset(gca,<span style=\"color: #A020F0\">'YLim'<\/span>,[0 1.1])\r\nlegend({colheaders{2:-1:1}})<\/pre>\n<div align=\"center\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/michael_katz_open_as_text\/y_vs_rs_orig.png\" alt=\"Original plot of yankees vs red sox\">\n<\/div>\n<p>Looking over the data, I notice that my friend has made a mistake by sending me an older version of the file that does not have the Yankees&#8217; most recent win. Rather than send him an email and wait an indeterminate amount of time for the new file, I&#8217;ll just go ahead and edit the file locally. Obviously, we can&#8217;t edit the file by double clicking since that brings up the Import Wizard, instead, let&#8217;s right-click and select open as text. <\/p>\n<div align=\"center\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/michael_katz_open_as_text\/open_as_text.png\" alt=\"open as text on context menu\">\n<\/div>\n<p>This opens the file in the Editor, now we can quickly add 2009 to the bottom of the list, save and replot. Voila!<\/p>\n<div align=\"center\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/michael_katz_open_as_text\/y_vs_rs_fixed.png\" alt=\"Fixed plot of yankees vs red sox\">\n<\/div>\n<p><strong> EDIT<\/strong> (25-01-2010): fixed typo in <tt>open<\/tt> command example<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I bet good odds that most of our users don&#8217;t know about the &#8220;Open As Text&#8221; feature in the Current Folder Browser. Double-clicking on files in the Current Folder will try to open the&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2010\/01\/25\/open-as-text\/\">read more >><\/a><\/p>\n","protected":false},"author":38,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,9],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/360"}],"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\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=360"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/360\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}