MATLAB - Blinkdagger Needs Your Help!
13 Jul 2008 Quan Quach 9 comments 1717 views
One of the things that has been annoying me lately is that some of our older posts refer to “MATLAB” as “Matlab”, an egregious error on our part. What’s the easiest way to remedy this problem? Can MATLAB help us fix this problem?
Contents
The Problem Description
The MATLAB capitalization mistake wasn’t brought to my attention until after we had published about 40 posts, so to go back and correct it manually would take a Herculean effort. Thus, we were thinking that a MATLAB script would come in handy. I was about to write a MATLAB function to help me fix this error, but then I thought it would be a good chance for one of our readers to show off their MATLAB prowess by helping us with this little problem.
The Desired Solution
You can download the sample input file here. (Right Click the link and use “Save As”) The sample file is the HTML code for the Slider Tutorial.
- The MATLAB function should be able to take in as input the name of a text file. To further elaborate, the input to the function should be a string which represents the input file’s name. In this case, the input will be:
'MATLAB GUI Tutorial - Slider.txt'Note: There are plenty of ways to code this part of the function, and we don’t really care how it is done as long as it gets the job done. You might find the
uigetfilecommand to be useful here as well! - The function should search within the text file for any incorrect instances of MATLAB such as
Matlab,matlab, orMatLaband replace it with MATLAB. - The output of the function should be a text file with the same name of the input file, but with an “_fixed” appended to the end of the file name. For example, if the input file is named “test.txt”, then the output file should be named “text_fixed.txt”. For this particular example, the output name for the text file should be:
'MATLAB GUI Tutorial - Slider_fixed.txt' - The contents of the output file should be identical to the contents of the input file, save any corrections related to the capitalization of MATLAB. A good way to see if the output file is correct is to change the extension of the text file from .txt to .html, and then open it. Hopefully everything should be the same from the input file!
- Extra Work: Since we have over 40 posts to correct, it would be nice if this process could be automated to fix all text files within a given directory.
Posting your Code
You can post your code in the comments section in the following method:

What’s in it for Me?
Unfortunately, we don’t have much to offer in prizes and riches. But, if we choose to use your code, we will feature you in a future Blinkdagger post, cementing your MATLAB legacy on the world wide web. Good luck, and thanks to everyone who decides to contribute!
9 Responses to “MATLAB - Blinkdagger Needs Your Help!”
Leave a Reply
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>


Something like that, perhaps?
Hello Ymihere and Blake,
Thanks for your submissions! On first glance, it apperas that both of them will work. I’m going to have to run them to see if the output is as expected. Will update you guys.
Quan
Both functions tested, and confirmed working! Thanks fellas!! I always enjoy reading other people’s code because I can learn so much from it. My coding style is drastically different, so it can be difficult to read other’s code sometimes, but well worth it!
Quan
Hey Quan,
Here is my contribution to the matlab/MATLAB effort. Hopefully you find the file-handling part helpful so you can select multiple files and also pick a different destination directory if you want.
Enjoy, Rob
Seems like I am the only one who didn’t know the textscan function.
Ymihere.
You weren’t the only one . ..
Personally, I would use the following perl one-liner to in-place replace all .txt files in a directory (backing up each fiile to .txt.old):
perl -i.old -pe “s/matlab/MATLAB/gi;”
Anyway, here’s my MATLAB implementation. It takes either a file or a directory as input. Also, I altered the code so that capitalization doesn’t get altered if it looks like “matlab” is part of a file path.
Hey Arthur,
Thanks for the submission. I just recently went back and renamed all our folders to MATLAB or else our images wouldn’t show up!
Quan