Inside the MATLAB Desktop
May 5th, 2008
File and Folder Comparison Tool Update in R2008a
I’d like to welcome guest blogger Malcolm Wood from the Simulink Model Management team. Malcolm will occasionally be blogging here on the Inside the MATLAB Desktop blog.
For many years the MATLAB Desktop has included a simple tool for comparing text files. You may have used it from the MATLAB Editor to see the changes you have made to your M-file since you last saved it, or you may have used it from the Directory Browser to compare two files on disk.
In R2008a we extended the capabilities of this tool to compare files which aren’t just plain text. You can now use it to compare the variables in MAT-files. It will tell you the names of the variables which are in each file, and for the variables which appear in both files it will tell you whether their values are the same or not:
And if you want to see exactly what’s different about these two variables called “X”, then clicking on either one will open it in the Variable Editor so that you can take a closer look.
For other types of binary file, the MATLAB will scan the two files and simply tell you whether their contents are the same or not.
You might have noticed from the screenshot above that the title is “File and Directory Comparisons”, namely because another new feature is the ability to compare entire directories. We think this sort of thing is useful for cases where you’ve taken a copy of some files and made some changes to get them to work for you. By comparing the two directories you can quickly review all the changes you made without leaving MATLAB.
This tool is available from the Directory Browser: just right-click on a directory and choose “Compare Against…”.
If the two directories you compare contain files of the same name, MATLAB will scan those files to determine whether their contents are the same or not. If they’re not, you’ll see a hyperlink to compare the files in detail.
If there are sub-directories with the same name but different time-stamps, there will be a hyperlink to let you compare the contents of those too.
We hope you’ll find these new features useful. And if there are changes you think we should make, leave us a comment to let us know!
-by Malcolm Wood, The MathWorks
By
Ken Orr
Ken is a developer on the MATLAB Desktop team. He loves the art of graphic design as well as developing visually pleasing user interfaces - he's one of those 'crazy' Mac guys!
7:20 am |
Posted in Current Directory, Editor |
Permalink |
8 Comments »
April 28th, 2008
Code Folding Update in R2008a
We heard your requests, and have added 12 more foldable constructs, including full support for the new MATLAB class system. We introduced code folding back in R2007b (check out the blog entry on it here), and quickly heard that folding only functions and function help was not enough. This is a great example of how your feedback really can affect things.
All these new foldable constructs can really help to hide detail that you may not always need to see (possibly the internals of a switch/case block). This is especially useful if your working on two non-contiguous areas in a file. Normally, this would require lots of scrolling, but with code folding, you can just collapse all the constructs between the two areas (you could also use split screen, but I prefer the folding technique).
Here’s a look at edit.m, the same file Christina showed back in November 2007, only now there are a lot more foldable regions:
And the new code folding preferences page:
Just as with the original two foldable constructs, you can choose which constructs you’d like to be folded by default. So if you want switch/case blocks to be folded whenever you open a file, select Fold Initially next to Switch/case blocks in the Editor/Debugger -> Code Folding preferences pane.
Also note that once you’ve opened a a file and tweaked what’s folded and what’s expanded, the MATLAB Editor will remember the fold state of that file even after you’ve closed it. So the next time you open your file, everything will be just as you left it.
If there are things you think should be foldable, that we’re not folding, leave us a comment here.
By
Ken Orr
Ken is a developer on the MATLAB Desktop team. He loves the art of graphic design as well as developing visually pleasing user interfaces - he's one of those 'crazy' Mac guys!
6:11 am |
Posted in Editor, Preferences |
Permalink |
No Comments »
April 21st, 2008
Variable Editor
When the Array Editor was introduced back in MATLAB 5.0, it provided static snapshots of MATLAB double arrays. It has evolved a lot since then, to provide dynamic editors for…
A lot of new functionality was added in R2008a, including
Because of all of these changes since Version 5, we felt that it was time to rename the Array Editor. It’s now called the “Variable Editor” to reflect its enhanced capabilities.
Let’s take a look at some of the changes. Create a variable and open it in the Variable Editor:
>> x = magic(10);
>> openvar x % Or go to the Workspace and double-click on x.
Here we see the Variable Editor with a new information bar bar located just below the toolbar. It shows the name, size, and class of the current variable, as well as the same icon (based on data type) that’s shown in the Workspace.
We also see the new data brushing toolbar button. Data brushing is a topic unto itself, worthy of a future posting (stay tuned - if you can’t wait to try it, checkout the documentation).
Structure Editing
We’ve enhanced structure editing to leverage a lot of the features that have been added to the Workspace in recent years. To see this, let’s create a structure with some interesting data.
>> s.data = magic(10);
>> s.city = ‘Natick’;
>> s.temp = 70.2;
>> openvar s
As you can see, the Variable Editor shows the fields of the structure in the same way that the Workspace shows the variables in the Workspace. Field (instead of Name), Value, Min, Max, and all of the other columns accessible in the Workspace are also shown here. Further, all of the gestures for editing (clicks, context menus, and so on) are identical to those used in the Workspace.
Object Editing
We’ve also added support for MATLAB class system objects. Now, the public properties of objects are shown in the same way as the fields of structures.
Let’s examine an instance of the memmapfile object:
>> m = memmapfile(which(’clown.mat’));
>> openvar m
Notice that the public properties of the object appear in the Variable Editor.
Normally, only the public properties of an object are visible. But if you’re debugging an object, you’ll need to be able to get to the protected or private properties, too. The Variable Editor supports that. Let’s set a breakpoint in one of the methods of memmapfile, and watch what happens.
>> edit memmapfile
Set a breakpoint on the set.writable method (in R2008a, that’s line 132) by right-clicking on that line and selecting “Set/Clear Breakpoint.”
Now, do something to hit that breakpoint:
>> m.writable = false;
The debugger stops on that line of code. In the Editor, you can see that the object being debugged is called “obj”. To see the contents,
>> openvar obj
The Variable Editor opens, showing all of the properties, both public and private. The ones that end users normally have access to are shown without any lock icons next to them. In contrast, the private properties have little red locks next to them, to show you that they’re normally inaccessible. You can only see them because you’re debugging one of the object’s methods.
These enhancements to Variable Editor should help to make interactions with your data more seamless. Let us know which Variable Editor enhancement you use most!
By
Bob Gilmore
Bob Gilmore manages the Plotting and Data Exploration development team at The MathWorks. He will be writing occasionally about tools for importing, managing, and exploring data in MATLAB.
6:39 am |
Posted in Data Tools |
Permalink |
3 Comments »
April 14th, 2008
A Link to the Data
In Release 2008a, we added the ability to link plots to source data. With this feature, you tie a plot to a particular value in the workspace. When that value changes, the plot is automatically updated, with no further intervention on your part.
For this release, we’ve made a short video tutorial explaining how to use this feature, with a particularly useful application: watching your variables change during a debugging session. The second half of the video covers another new feature, data brushing, which is a topic for a later post.
One use not covered in the video is for observing real-time data. A while back I wrote a program to monitor incoming bytes from the serial port and update a graph with that data: a serial “oscilliscope”, if you will. In order to achieve smooth scrolling, instead of re-plotting the data, I modified the axes’ Xdata and Ydata properties whenever there were
BytesAvailable. This was a cumbersome hack.
With this new feature, I can just use the data callback function to update my variable in the workspace and let the plot and linkdata objects do the heavy lifting.
The following real-time example uses the yahoo function from the Datafeed Toolbox. The same principles can be applied to any asynchronous callback in MATLAB, such as the above-mentioned BytesAvailableFcn for a serial object, most of the objects from the Data, Instrument, or Image Acquisition Toolboxes, Simulink and the target link toolboxes, or even a GUI control callback. This code uses a timer object to query AT&T’s stock price every 10 seconds, and adds that value to an array in the workspace.
Because the plot is linked to the data, the plot automatically updates to reflect the new value, thus giving us a real-time stock ticker.
close all;delete(timerfindall);clear all;
Connect = yahoo; %Datafeed Toolbox function
val=[];
time=[];
t = timer(‘TimerFcn’,…
[‘data = fetch(Connect, ”t”,”last”);’…
‘val(end+1) = data.last;’…
‘time(end+1)=rem(now,1);’] ,…
‘Period’, 10,‘ExecutionMode’,‘fixedRate’);
start(t) %start the timer
%unambiguously set the source data
plot(time,val,‘XDataSource’,‘time’,‘YDataSource’,‘val’)
title(‘Price of AT&T’)
linkdata on %link the the data to the plot
Watching a stock fluctuate over a few minutes isn’t generally exciting, but you get the idea. What’s the big deal, then? I think this feature is best for when we don’t know when the data is going to change (but that it will), or when you want change the data iteratively and interactively without having to do a lot of retyping, as in the following example.
I like linking for situations where one is tinkering around with a variable in the command window. For me this is usually applying different filters to some data until I get the parameters just right. For instance, let’s say I have some data and I want to tweak filter coefficients until I get the desired response on my data. The following example requires the Signal Processing Toolbox.
First let’s set up the data:
t = linspace(0,6*pi,100);
x = sawtooth(t); %sawtooth wave - Signal Processing Toolbox function
y = x;
plot(abs(fft(y)))
This time let’s use the GUI to set the YDataSource by clicking the link button: . Then, click the “fix it” link (1) in the message bar, and then enter a fft expression in the YDataSource field (2).
Now let’s try out a 2nd-order butterworth filter. We won’t have to manually re-FFT or re-plot the new output:
[a,b]=butter(2,0.1); %Signal Processing Toolbox function
y = filter(a,b,x);
Close, but not quite, so I’ll try upping the order to 4:
[a,b] = butter(4,0.1);
y=filter(a,b,x)
Good enough! Of course I could have just as easily put the whole filter expression in my YDataSource instead, saving me an extra line.
I invite you to let us know what other creative uses for this you come up with. Do I hear animation?
By
Michael Katz
Mike is a developer on the MATLAB Desktop 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.
5:58 am |
Posted in Data Tools |
Permalink |
14 Comments »
April 7th, 2008
The Tools You Want Where You Want Them
That title sounds like somebody’s advertising catch phrase, but what I’m referring to is the toolbar customization and rearrangement capability that was added to the MATLAB desktop in R2008a. This is, of course, nothing revolutionary, but it is new to MATLAB (I almost tripped on another catch phrase there). If you right-click (Command-click on Mac) on the main desktop toolbar or on either of the Editor toolbars, the context menu will offer a “Customize…” option. Selecting this option will display a Toolbar Preferences panel within the Preferences Dialog:
You can use this panel to specify which controls you want to appear on a toolbar and in what order. To add and remove controls simply check and uncheck the corresponding entries in the list that occupies most of the panel. As you check and uncheck controls, they appear and disappear from the layout area above. Within the layout area you can then rearrange the controls you have selected by dragging them.
For an example of what you might do with this capability here is my customized Editor toolbar:
I always use the keyboard shortcuts for Cut, Copy and Paste so I removed those buttons. The buttons I use the most are the ones that control debugging so I moved them to the beginning. I moved Print and Publish to the end of the toolbar since I don’t happen to make much use of them. This way, if I make my editor narrow, my favorite buttons don’t drop off the end of the toolbar.
As for my main MATLAB toolbar and the Shortcuts toolbar I’ve configured them as follows:
I again removed Cut, Copy and Paste. Furthermore, I haven’t found much use for Undo and Redo outside the context of the Editor so they’re gone too. This shortened the main toolbar a bit. I took advantage of this extra space by dragging my Shortcuts toolbar to be adjacent to the main toolbar. I now have all the tools I want on a single row, leaving more working real-estate.
One reason I’m excited about the customization capability is that it allows us to offer a more extensive palette of toolbar controls in the future without cluttering everyone’s toolbar with all possible controls.
It dawned on me that my recent posts have discussed the Document Bar, Title Bars and now ToolBars. Maybe I should change my e-mail signature to
Peter Muellers
Desktop Bar Tender
The MathWorks, Inc.
By
Peter Muellers
Peter Muellers is a developer on the MATLAB desktop team. He works primarily on the desktop framework. Many of his better ideas occur while he is running, biking or sleeping.
6:44 am |
Posted in Desktop, Editor, Preferences |
Permalink |
No Comments »
March 31st, 2008
Help us help you
If you are a regular reader of this blog, you are probably already aware that we monitor your comments closely. In fact, we’re always looking for ways to get feedback from MATLAB users. Along with the great feedback we get through technical support and our user surveys, we’re continually checking the file exchange and the MATLAB Newsgroup for your ideas.
Our documentation group is just as interested in hearing from you as our developers are. Starting with R2007b, nearly every page in the Help browser includes links to a feedback form at the top
and bottom
of the page. The online documentation on our web site contains links to the same feedback form.
You can be as specific as you want about the page you’re commenting on - the form keeps track of which page you were viewing when you clicked on the feedback link. Or, if you couldn’t find what you were looking for, feel free to give us feedback about the page on which you expected to find a topic. Each request will be routed to the appropriate writer and taken into consideration for the documentation of the next release. If you include your email address in your feedback, you can expect to hear back from the writer with any comments or questions they might have, as well as a summary of any action they are taking as a result of your feedback.
So, if you couldn’t have done your job without our documentation, let the writer know. If you think you have an example that’s even better than the one we provide, we want to know about that too. We’ve already gotten lots of good feedback from you; nearly half of the comments we have received have directly resulted in improvements and corrections in our documentation. You’ve shown us that you can make our documentation better, and we want you to keep it up. Our documentation team looks forward to hearing from you!
By
Chris Kollett
Chris is a developer on the MATLAB help team. When he's not working on the Help Browser, he can often be found at Fenway Park.
5:50 am |
Posted in Help Browser |
Permalink |
No Comments »
March 24th, 2008
Publishing made easy with publish configurations
The publish function has been around since R14 and has proved useful for a number of things, to include demonstrating concepts, creating reports and generating blogs. In R2008a we’ve made it easier to fit publishing into your work flow, by introducing publish configurations, younger brother to run configurations (introduced in R2007b).
The most significant change is that you can now have multiple sets of publish options associated with a single file - previously there was a single set of global publish options. This added flexibility allows you to more easily publish different files with different options and even publish the same file with different options.
To get aquatinted with this new feature, let’s look at how our very own Loren of Loren on the Art of MATLAB uses publish configurations in her workflow.
Loren’s Workflow:
After composing the first draft of her entry in the MATLAB Editor, Loren likes to check the spelling and grammar of the file. The easiest way to do this, is to publish the document to Word format, and then open the published output in Word. It’s important to publish the document first, as this ensures that she’s viewing the same content that the reader will be seeing.
Once Loren is happy with the entry, it’s time to publish it to HTML. One of the restrictions when publishing her blog is the width of the images - too wide an image causes scroll bars and layout problems, so she likes to restrict image width to 500 pixels.
Here’s are the steps Loren follows in order to take advantage of this new feature:
Draft Phase - Publishing to Word
Step 1: Once the draft is ready for spelling and grammar checking, open the configuration editor by clicking the drop down arrow next to the publish button and select Edit Publish Configurations for [your_file.m]:
This automatically creates a publish configuration with the name of your file (’foo’ in the figure above). You can also specify input to the function you’re publishing, as I’ve done above.
Notice that there are two sets of Publish Settings that ship with MATLAB: Factory Default and User Default. Every new publish configuration you create, will use the User Default settings, which you can change if you’d like (see the doc for how to do this). But you can also create custom sets of settings. In the next two steps we’ll create a custom set of publish settings that we can use now and in the future each time we want to spell check and grammar check our work.
Step 2: Change the Output file format to doc:
Notice that a dot is shown next to the Output file format setting, indicating that our settings have deviated from the User Default settings.
Step 3: Now click Save As… in the configuration editor and type Word for the Settings name in the Save Publish Settings As dialog. When you’ve finished typing the name click Save:
This creates a new set of publish settings that will be used in the current publish configuration. These new settings will also be available to use in other publish configurations via the Publish Settings combo box:
Step 4: Click Publish in the configuration editor and review the document.
Blog Phase - Publishing to HTML:
OK…the spelling and grammar have been checked and we’re ready to upload the blog entry to the web. Next we’ll open up the configuration editor again, create a new publish configuration and create another set of reusable publish options for blog posts.
Step 5: Press the add button in the configuration editor and select Publish Configuration:
This creates a new publish configuration associated with your file, which is named ‘foo_2′ in the example above. This configuration uses the User Default publish settings, and because the default output format is html, we don’t have to change this setting.
Step 6: Now change the Max image width (pixels) to 500:
Finally, press Save As… in the configuration editor and type Blog for the Settings name and click Save (as we did above).
Step 7: Click Publish and upload to the web!
End State:
Loren’s MATLAB file now has two publish configurations, one using the Word publish settings, and one using the Blog publish settings. Each time Loren creates a blog entry, she can create a publish configuration for her MATLAB file and select the publish settings appropriate for her current task (spelling and grammar checking or getting ready to upload to the web).
MATLAB saves all the configurations for every file, as well as the publish settings that are used within the configuration. This makes it easy for Loren to consistently publish a file with the same settings.
Give Publish Configurations a Try!
Your work flow and ultimate product may be different from Loren’s, but the publish configurations can reap the same work flow benefits for you. Let us know how you use this feature!
By
Ken Orr
Ken is a developer on the MATLAB Desktop team. He loves the art of graphic design as well as developing visually pleasing user interfaces - he's one of those 'crazy' Mac guys!
6:08 am |
Posted in Configuration Editor, Editor, Publish |
Permalink |
6 Comments »
March 17th, 2008
What’s on my TODO list?
Oftentimes in the course of coding, I find myself with little bits that I don’t want to deal with right away–things that I would like to come back to them later. Like most IDEs, MATLAB allows you to drop annotations which indicate things to do, fix, or otherwise note for later.
By adding a comment with the text: “TODO” or “FIXME” in a MATLAB file, you automatically sign up for this feature. You can then use the TODO/FIXME report to scan all the files in a given directory for these tags, which presents the results to you in the web browser.
You can get to this report using the directory reports-drop down in the Current Directory Browser:
Clicking on the TODO/FIXME report button will cause MATLAB to scan all the files in the current directory, and display each line in the files that have one of the keywords. For example, in my directory I have two files with applicable markers:
You’ll notice that the report also picked up a line with a “NOTE” in it. As an added bonus, we can find up to one additional comment tag, “NOTE” by default, but you can enter whatever regular expression you desire. To specify your own custom tag, replace the text in the text field that reads “NOTE” in the TODO/FIXME report web page (see above screen shot) with your own regular expression.
In general, I recommend using these comments as quick reminders for changes you really, really will work on in the near future. I’ve found such notes lose meaning when viewed by others or even yourself when revisiting the code after it is no longer fresh.
By
Michael Katz
Mike is a developer on the MATLAB Desktop 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.
6:10 am |
Posted in Current Directory, Editor |
Permalink |
1 Comment »
March 10th, 2008
New and Updated Desktop Features in R2008a
R2008a is here and there are a number of great new features in the desktop. I’m only going to give a brief introduction to each of these shiny new features, though in future entires, we’ll explore them in greater detail.
If you see something that’s particularly interesting, leave a comment. The more comments about a feature, the sooner we’ll blog about it!
|
The Desktop and Editor now allow you to customize their toolbars. You can change the order of toolbar elements, or remove things you rarely use.
Customizable toolbars will really help stream-line your workflow, as you can arrange your toolbars based on how you use MATLAB.
|
|
Publish Configuration’s allow you to specify options to be passed to the publish function when you press the publish button. Publish Configurations work very similarly to Run Configurations, in that they can be edited in the Configuration Editor and are associated with a particular file.
In previous releases, there was one set of preferences that applied whenever you pressed the publish button. Now, you can create multiple sets of options for a given file. For example, you can have a configuration that publishes to Word and another that publishes to HTML.
|
|
We’ve added a whole bunch more foldable constructs. Here’s the complete list of what you can now fold in the MATLAB Editor:
- Block comments
- Cells used for rapid code iteration and publishing
- Class code
- Class enumeration blocks
- Class event blocks
- Class method blocks
- Class properties blocks
- For and parfor blocks
- Function and class help
- Function code
- If/else blocks
- Switch/case blocks
- Try/catch blocks
- While blocks
|
|
Data brushing is a new feature that lets you manually select data on a plot. This tool really fosters manual interaction and exploration of your data.
Linked plots are graphs that respond to backing data changes. The underlying data and plot are tied together, so a change in one, causes a change in the other. This is useful if you have multiple plots representing the same data, as you need only update the data in a single place in order to update your plots.
|
|
The Variable Editor now provides enhanced editing of Structures and Objects.
|
|
The File Comparisons tool has been enhanced to support directory comparisons. Its name has also unsurprisingly been changed to the File and Directory Comparisons tool.
|
By
Ken Orr
Ken is a developer on the MATLAB Desktop team. He loves the art of graphic design as well as developing visually pleasing user interfaces - he's one of those 'crazy' Mac guys!
5:59 am |
Posted in Configuration Editor, Data Tools, Desktop, Publish |
Permalink |
11 Comments »
March 3rd, 2008
Sharing Your M-Lint Settings
Writing robust, production quality MATLAB code is a whole lot easier when you use M-Lint. M-Lint inspects your code for problems and also recommends changes that will help improve the performance or maintainability of your code. M-Lint is analogous to the spelling and grammar checkers I so depend on, available in most word processors.
In order to really take advantage of M-Lint, I’ve found it useful to integrate it into the code review process. So when working on a team project, we use an agreed upon set of M-Lint settings, which are stored on a public drive. Then, each developer points their M-Lint analyzer to those settings, and codes against them.
Finally, when completing a code review, one of the exit requirements is that the MATLAB code must be in a “green” state (no errors, no warnings). We do allow warnings to be ignored using %#ok, though good justification must be provided.
Here’s how you can set up shared M-Lint settings:
The person setting up the shared settings should do the following
- Open the Preferences dialog by going to File -> Preferences… and select M-Lint (you should see the dialog below)
- Tweak the M-Lint settings as needed
- Press Save As…
- Navigate to a shared directory and press Save (alternatively you could check this file into source control)
Each team member should do the following
- Open the Preferences dialog by going to File -> Preferences… and select M-Lint
- Click on the Active Settings combo-box and select Browse…
- Navigate to your teams shared M-Lint settings, select that file and click Open
- Press Apply or OK for the settings to become active.
Many of us work on multiple teams, so I should point out that it’s very easy to switch between M-Lint settings. Go to Tools -> M-Lint and select the appropriate settings for the project your working on.
I think you’ll find this approach really makes you think about your warnings, and it will force you to justify any usages of %#ok.
By the way, there’s a new blogger in the family. Seth will be talking about Simulink over at his new blog, Seth On Simulink. This will be a great place for Simulink users to pick up tips and tricks, as well as share their experiences with the product.
By
Ken Orr
Ken is a developer on the MATLAB Desktop team. He loves the art of graphic design as well as developing visually pleasing user interfaces - he's one of those 'crazy' Mac guys!
7:09 am |
Posted in Editor, Preferences |
Permalink |
4 Comments »
|
|
These postings are the author's and don't necessarily represent the opinions of The MathWorks.
|
|
Recent Comments