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.
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}})
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.
This opens the file in the Editor, now we can quickly add 2009 to the bottom of the list, save and replot. Voila!
EDIT (25-01-2010): fixed typo in open command example
By
Michael Katz
Mike is a developer on the MATLAB Mobile team. When not describing himself in the third person, biking, homebrewing, or rooting for the home team, he's busy trying to make the world a better place for programming.
15:38 UTC |
Posted in Current Directory, Editor |
Permalink |
2 Comments »
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
|
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.
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.