MATLAB Community

MATLAB, community & more

Did you know that MATLAB has a diff tool?

Have you ever found a new feature in an application that you use daily and then wondered, “How did I not notice that before?”While using MATLAB a few weeks back, I discovered a feature that I had never noticed before that has been a part of MATLAB for a full year now; since MATLAB 7.3 (R2006b), MATLAB has had a diff tool built into it.

Some might be wondering, “What is a diff tool?” A diff tool allows you to compare two files against each other so that you can see where the differences between them are. I find that using a diff tool can be very helpful just before I checkin code after adding a feature or fixing a bug. By looking at the differences between my file and the original version of the file I can very easily review all of my changes to the file. This helps ensure that the code that I am checking in is correct.

You might be saying, “So how do I use the diff tool from within MATLAB?” It is actually very easy to get to. I recently decided to update one of my contributions on the MATLAB Central – File Exchange and when I was done I wanted to use the diff tool to see what I had changed. In the Current Directory window, if you select two files (by holding in the Control key while selecting the files) and then right click on the files, you will see the context menu shown below:

Current Directory file selection context menu

After clicking, “Compare Selected Files,” a new window is opened with the changes highlighted:

Old search_path.m compared with the new searchPath.m

Diff tools are not perfect, and sometimes they show changed lines as new lines, but the view that they provide can really help you know where things have changed within your code.I was really happy when I found this feature was built into MATLAB. Let me know once you give this tool a try, and if like me, you find this very useful.

|
  • print

댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.