Matlab Logo 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.

  1. 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 uigetfile command to be useful here as well!

  2. The function should search within the text file for any incorrect instances of MATLAB such as Matlab, matlab, or MatLab and replace it with MATLAB.
  3. 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'
  4. 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!
  5. 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:

pasteCode.png

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!