Mike on the MATLAB Desktop

January 25th, 2010

Open as Text

I bet good odds that most of our users don’t know about the “Open As Text” feature in the Current Folder Browser. Double-clicking on files in the Current Folder will try to open the file using MATLAB’s implementation of the open function. That means importing to the workspace for a data file, loading of a mdl-file in Simulink, and editing a regular “.m’ 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.

Let’s say I wanted to compare the years the Yankees and Red Sox won the World Series. To do this, I’ll have my friend over in the facts department sent me a tab-delimited file with the years each team won the World Series, “ws.dat”. Double-clicking it in the Current Folder Browser does the same operation as the MATLAB command open('ws.dat'), that is, the Import Wizard is launched and the data can be imported into the workspace.

Double-click to import

With this imported data, we can quickly visualize the years that each team won the World Series (I’ll leave it as an exercise for the the reader to interpret the results).

cla
hold on
bar(data(:,2),repmat(1,1,27),'r')
bar(data(:,1),repmat(1,1,27),'b')
set(gca,'YTickLabel',[])
set(gca,'YTick',[])
set(gca,'YLim',[0 1.1])
legend({colheaders{2:-1:1}})
Original plot of yankees vs red sox

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’ most recent win. Rather than send him an email and wait an indeterminate amount of time for the new file, I’ll just go ahead and edit the file locally. Obviously, we can’t edit the file by double clicking since that brings up the Import Wizard, instead, let’s right-click and select open as text.

open as text on context menu

This opens the file in the Editor, now we can quickly add 2009 to the bottom of the list, save and replot. Voila!

Fixed plot of yankees vs red sox

EDIT (25-01-2010): fixed typo in open command example

2 Responses to “Open as Text”

  1. OysterEngineer replied on :

    This is a handy feature to have. Thanks for covering it.

    It seems like you’ve introduced a couple recent columns with something like, “. . . many users likely don’t know this . . .” Which begs the question, when The MathWorks decided to invest the effort to develop these features, what was their vision for making the user community aware of the feature? I generally browse the Release Notes & have reviewed them again this morning, looking for some mention of this feature. Of course, I haven’t done an exhaustive search. But, I haven’t found any discussion of this.

  2. Mike replied on :

    OysterEngineer,

    “Open as text” and “delete next word” are capabilities that have been in the product for a long time, and at the time they were introduced we didn’t have as many ways of advertising features as we do now. That’s part of the reason why I’ve decided to discuss them on the blog.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks
Mike works on the MATLAB Desktop team.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.