Inside the MATLAB Desktop
May 27th, 2008
Getting to your configurations
Back when we introduced configurations in R2007b (see this blog entry), one of the first questions brought up by customers was “where are the configurations stored and what format are they in?”. A completely understandable request, as it can be disconcerting to put time and energy into something and not know what controls the fate of your hard work (i.e. what happens if I upgrade MATLAB or move to another machine?).
We heard your requests and have made both run and publish configurations accessible. You can find your configurations by cd‘ing to prefdir:
>> cd(prefdir)
You’ll find a number of files in this directory - the two we’re interested in are run_configurations.m and publish_configurations.m. These two files are both MATLAB files that use cell mode. You can open up the raw run and publish configuration storage files in the MATLAB editor for viewing, but you shouldn’t edit these files directly (see note below).
NOTE: Do not edit run_configuration.m or publish_configuration.m within the MATLAB Editor - use either the Configuration Editor, or modify the files from a text editor when MATLAB is not running.
Here’s what the beginning of my run_configurations.m file looks like:
% MATLAB Run Configurations
% @version 2
% It is recommended that you do not edit this file directly, but use the
% Configuration Editor provided in MATLAB. Changes made to comments that
% exist outside of a configuration will not be saved.
%% @name foo
% @associatedFile /mathworks/home/korr/Desktop/foo.m
% @mostRecentlyActioned false
% @uniqueId -4e3eabb0:11a2a50508e:-7f8f
% Modify expression to add input arguments.
% Example:
% a = [1 2 3; 4 5 6];
% foo(a);
x = 1:100;
foo(x);
disp(‘Done running foo.’);
You can share this file with others, though there currently isn’t a way to import another run or publish configuration file. With MATLAB shutdown, the receiving user can either copy and paste the desired configurations into his own configurations file or rename his configurations file from run_configurations.m to something like run_configurations_old.m.
If the receiving user doesn’t have a MATLAB file that a configuration is linked to, the Configuration Editor will indicate the problem by placing a red x next to the file name:
To fix this problem, point the Configuration Editor to the MATLAB file that the configuration corresponds to by editing the Associated M-File text field, or by clicking Choose… to navigate to the file.
We’d love to here what enhancements you would like to see in the Configuration Editor!
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!
8:53 am |
Posted in Configuration Editor |
Permalink |
No Comments »
May 19th, 2008
Stop in the name of error
Recently I was performing some maintenance on the Dependency Report tool. The report has logic to display something reasonable in the web browser even if the scanned directory contains invalid MATLAB files. To make that work, there are several try/catch blocks that the process various errors that may be encountered.
When I tested my new changes in a directory with some “bad” MATLAB files…let’s just say that the code was not handling the errors properly! Normally in these situations I type:
dbstop if caught error
and inspect the state of program in the editor. However due to the recursive, iterative, and nested nature of this code, there were too many caught errors in different files to make this an efficient process. That’s when I remembered that we can stop on a particular type of error, but I could not remember the syntax to do so.
Debug menu to the rescue!
I clicked Debug -> Stop if Errors/Warnings… to open the Stop if Errors/Warnings for All Files dialog.
Next, I needed a unique error identifier, so MATLAB would know where to halt execution. This is easy to do from the command prompt using the lasterror command:
>> lasterror
ans =
message: 'Index exceeds matrix dimensions.'
identifier: 'MATLAB:badsubscript'
stack: [1x1 struct]
Then, I cut and pasted the identifier into the Stop if Errors/Warnings for All Files dialog. To follow along, Click the “Try/Catch Errors” tab (1), select “Use Message Identifiers” (2), and click “Add” (3):
Finally, I pasted in the message I was interested in and clicked “OK”:
After this, I re-ran my code. Execution stopped only when this error was caught, which allowed me to debug just this issue.
Incidentally, the command-line syntax is shown in the dialog; hopefully I will remember that for next time!
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:20 am |
Posted in Editor |
Permalink |
1 Comment »
May 12th, 2008
Brush up on your data
We’ve already received great feedback on Data Brushing, a new MATLAB R2008a feature that is closely related to Data Linking.
Data Brushing allows you to graphically edit the data in a plot, allowing you to clean up the data, or focus in on a particular region. Unlike Plot Tools, which allow you to edit the graphics of the plot (labels, legend, colors, etc), this feature works on the actual data in the plot.
Here I’ve taken the L-shaped membrane (MathWorks logo) and brushed the flat part. I changed the color of the brushing from the default red to hot pink for better contrast (The color can be changed by clicking the drop-down button next to the brush icon).
Right-clicking the brushed area gives options to delete the data (for cleaning up outliers), replacing the data with a new value, or various copy options. Here’s what happens if I replace the flat area with NaN’s:
You can also drag the highlighted region into Microsoft Excel or a text editor and it will give you a table of the highlighted data.
As a bonus, if you have data linking turned on, the changes are reflected back in the workspace. If you haven’t already watched the tutorial video, I suggest you take a look at it.
By combining brushing with linking, you get a nice tool for data exploration and data manipulation that allows you to work in one domain, when the data you care about is visualized in another domain. Two great uses come to mind: filter design and principal component anaylsis–basically anytime you want to look at the same data in multiple ways at the same time. The above linked video shows this with highway safety data.
These tools give a lot of flexibility and ease of manipulating graphs. Please exercise responsible presenting.
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:44 am |
Posted in Data Tools |
Permalink |
No Comments »
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 |
12 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 |
16 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 »
|
Recent Comments