377 relevant articles found:

Tips for accelerating Matlab performance

I’m proud to report that MathWorks has recently posted my article “Tips for Accelerating MATLAB Performance” in their latest newsletter digest (September 2017). This article is an updated and expanded version of my post about consulting work that I did for the Crustal Dynamics Research Group at Harvard University, where I helped speed-up a complex Matlab-based GUI by a factor of 50-500 (depending on the specific feature).

Crustal dynamics visualization GUI

Crustal dynamics visualization GUI

Continue reading

Prasad Kalane, Pati David liked this post
Categories: Handle graphics, Low risk of breaking in future versions
Tags: , ,
2 Comments

Faster csvwrite/dlmwrite

Matlab’s builtin functions for exporting (saving) data to output files are quite sub-optimal (as in slowwwwww…). I wrote a few posts about this in the past (how to improve fwrite performance, and save performance). Today I extend the series by showing how we can improve the performance of delimited text output, for example comma-separated (CSV) or tab-separated (TSV/TXT) files.

The basic problem is that Matlab’s dlmwrite function, which can either be used directly, or via the csvwrite function which calls it internally, is extremely inefficient: It processes each input data value separately, in a non-vectorized loop. In the general (completely non-vectorized) case, each data value is separately converted into a string, and is separately sent to disk (using fprintf). In the specific case of real data values with simple delimiters and formatting, row values are vectorized, but in any case the rows are processed in a non-vectorized loop: A newline character is separately exported at the end of each row, using a separate fprintf call, and this has the effect of flushing the I/O to disk each and every row separately, which is of course disastrous for performance. The output file is indeed originally opened in buffered mode (as I explained in my fprintf performance post), but this only helps for outputs done within the row – the newline output at the end of each row forces an I/O flush regardless of how the file was opened. In general, when you read the short source-code of dlmwrite.m you’ll get the distinct feeling that it was written for correctness and maintainability, and some focus on performance (e.g., the vectorization edge-case). But much more could be done for performance it would seem.

This is where Alex Nazarovsky comes to the rescue.
Continue reading

Categories: Low risk of breaking in future versions, Mex, Undocumented feature
Tags: , , ,
5 Comments

Runtime code instrumentation

I regularly follow the MathWorks Pick-of-the-Week (POTW) blog. In a recent post, Jiro Doke highlighted Per Isakson’s tracer4m utility. Per is an accomplished Matlab programmer, who has a solid reputation in the Matlab user community for many years. His utility uses temporary conditional breakpoints to enable users to trace calls to their Matlab functions and class methods. This uses a little-known trick that I wish to highlight in this post.

tracer4m utility uses conditional breakpoints that evaluate but never become live

tracer4m utility uses conditional breakpoints that evaluate but never become live

Matlab breakpoints are documented and supported functionality, and yet their documented use is typically focused at interactive programming in the Matlab editor, or as interactive commands that are entered in the Matlab console using the set of db* functions: dbstop, dbclear, dbstatus, dbstack etc. However, nothing prevents us from using these db* functions directly within our code.
Continue reading

Categories: Medium risk of breaking in future versions, Stock Matlab function, Undocumented feature
Tags: , , ,
3 Comments

Advanced Matlab online webinars

Advanced Matlab training webinars at the comfort of your desk I have prepared the following online webinars on advanced Matlab topics I (click the webinar titles for a detailed description):

All webinars are highly technical, concise and to the point, making very effective use of your time. They are based on onsite training courses that I presented at multiple client locations (details).

These webinars could be a great way for you to improve your Matlab proficiency and efficiency. You will quickly learn how to produce higher quality, better looking, faster working, and more robust applications. Your effectiveness in writing Matlab programs will improve, saving you development time while improving the quality. And all this at the comfort and convenience of your office or home.

 Email me if you would like additional information or a group discount, or to inquire regarding an onsite training course, or for any other related query/suggestion.

Categories: Public presentation
Tags: ,
Leave a comment

Matlab GUI training seminars – Zurich, 29-30 August 2017

Advanced Matlab training, Zurich 29-30 August 2017
Advanced Matlab training courses/seminars will be presented by me (Yair) in Zürich, Switzerland on 29-30 August, 2017:

  • August 29 (full day) – Interactive Matlab GUI
  • August 30 (full day) – Advanced Matlab GUI

The seminars are targeted at Matlab users who wish to improve their program’s usability and professional appearance. Basic familiarity with the Matlab environment and coding/programming is assumed. The courses will present a mix of both documented and undocumented aspects, which is not available anywhere else. The curriculum is listed below.

This is a unique opportunity to enhance your Matlab coding skills and improve your program’s usability in a couple of days.

If you are interested in either or both of these seminars, please Email me (altmany at gmail dot com).

I can also schedule a dedicated visit to your location, for onsite Matlab training customized to your organization’s specific needs. Additional information can be found on my Training page.

Around the time of the training, I will be traveling to various locations around Switzerland. If you wish to meet me in person to discuss how I could bring value to your project, then please email me (altmany at gmail):

  • Geneva: Aug 22 – 27
  • Bern: Aug 27 – 28
  • Zürich: Aug 28 – 30
  • Stuttgart: Aug 30 – 31
  • Basel: Sep 1 – 3

 Email me
Continue reading

Prasad Kalane liked this post
Categories: Public presentation
Tags: , , , , , , , , , ,
Leave a comment

Sending HTML emails from Matlab

A few months ago I wrote about various tricks for sending email/text messages from Matlab. Unfortunately, Matlab only sends text emails by default and provides no documented way to send HTML-formatted emails. Text-only emails are naturally very bland and all mail clients in the past 2 decades support HTML-formatted emails. Today I will show how we can send such HTML emails from Matlab.

A quick recap: Matlab’s sendmail function uses Java (specifically, the standard javax.mail package) to prepare and send emails. The Java classes are extremely powerful and so there is no wonder that Mathworks chose to use them rather than reinventing the wheel. However, Matlab’s sendmail function only uses part of the functionality exposed by these classes (admittedly, the most important parts that deal with the basic mail-sending mechanism), and does not expose external hooks or input args that would enable the user to take full advantage of the more advanced features, HTML formatting included.

Only two small changes are needed in sendmail.m to support HTML formatting:

  1. HTML formatting required calling the message-object’s setContent() method, rather than setText().
  2. We need to specify 'text/html' as part of the message’s encoding

Continue reading

Categories: Java, Low risk of breaking in future versions, Stock Matlab function, Undocumented feature
Tags: , , ,
Leave a comment

User-defined tab completions – take 2

Back in 2010, I posted about Matlab’s undocumented mechanism for setting Matlab desktop tab-completions. That mechanism used a couple of internal files (TC.xml and TC.xsd) to describe the various possible options that are auto-completed (or displayed in a small tooltip window) when the user clicks the <Tab> key on partially-entered function input parameters.

Using TabComplete for user-defined functions

Using TabComplete for user-defined functions

Unfortunately, this mechanism apparently broke in R2016a and was replaced with a new mechanism, as explained below.

The new mechanism relies on a file called functionSignatures.json which exists in every single folder that contains Matlab files that have functions whose input parameters ought to be tab-completable.

The new mechanism offers far greater versatility and flexability in defining the input types and inter-relationsships compared to the old TC.*-based mechanism. Another important benefit is that we can now add custom user-defined functionSignatures.json files to our user folders, next to our m-files, without having to modify any Matlab system file.
Continue reading

Categories: Desktop, Medium risk of breaking in future versions, Undocumented feature
Tags: , ,
5 Comments

Matlab Expo – Bern, 22 June 2017

Matlab Expo Bern - 22 June, 2017
Munich Germany Expo video, 10 May, 2016
My Matlab Expo 2016 keynote presentation (32:45)
(Matlab Expo 2017 presentation will be different)

MathWorks were very kind to invite me to speak at the upcoming annual Matlab Expo in Bern, Switzerland, on June 22, 2017 at 15:30. My presentation will be about “MATLAB Tricks You Need to Know“.

I also presented at last year’s Expo in Munich (you can see the video on the right). So in order not to bore the audience, my presentation this year will be completely different – it will not focus on any single program or industry, but instead provide content that should be relevant to a large portion of Matlab users.

My presentation will highlight several simple-to-use tips and tricks that can improve Matlab program usability and performance, and Matlab programming productivity in general. My aim is to show that Matlab can be used to create professional-quality applications, without sacrificing Matlab’s benefits (RAD, functionality, reliability), and that Matlab is certainly relevant for serious user-facing applications, not just for prototyping and internal organizational use.

I am targeting the presentation at anyone who uses Matlab, with any level of experience. Many of the tricks will be easy enough to use that even novice users could benefit, and some tricks might be useful even to advanced users. All these tricks are simple to understand, and yet very effective for improving run-time performance and visualization quality.

Participation in the Bern Expo is free, please don’t hesitate to come. If you’re considering it, then you might also be interested in my Advanced Matlab seminars in Zurich earlier that same week, on June 19-20.

If you are in the area and wish to meet me to discuss how I could bring value to your work, then please email me (altmany at gmail) to coordinate a meeting. We could meet either at the Expo, or in a dedicated (private) meeting.

Update June 23, 2017: I am extremely disappointed to report that my presentation at the Matlab Expo in Bern yesterday was not video-recorded. I thought that it went quite well so this makes me very sad. Anyway, you can see my presentation slides here. It doesn’t contain all the explanations and extra details that I communicated verbally, but I think that it might still be useful as-is. I hope you find it beneficial!

Matlab Expo Bern - 22 June, 2017 Matlab Expo Bern - 22 June, 2017

Categories: Public presentation
Tags:
3 Comments

Matlab compilation quirks – take 2

Once again I would like to welcome guest blogger Hanan Kavitz of Applied Materials. Hanan posted a couple of guest posts here over the past few years, including a post last year about quirks with Matlab-compiled DLLs. Today Hanan will follow up on that post by discussing several additional quirks that they have encountered with Matlab compilations/deployment.

Don’t fix it, if it ain’t broke…

In Applied Materials Israel (PDC) we use Matlab code for both algorithm development and deployment (production). As part of the dev-ops build system, which builds our product software versions, we build Matlab artifacts (binaries) from the Matlab source code.

A typical software version has several hundreds Matlab artifacts that are automatically rebuilt on a daily basis, and we have many such versions – totaling many thousands of compilations each day.

This process takes a long time, so we were looking for a way to make it more efficient.

The idea that we chose to implement sounds simple – take a single binary module in any software version (Ex. foo.exe – Matlab-compiled exe) and check it: if the source code for this module has not changed since the last compilation then simply don’t compile it, just copy it from previous software version repository. Since most of our code doesn’t change daily (some of it hasn’t changed in years), we can skip the compilation time of most binaries and just copy them from some repository of previously compiled binaries.
Continue reading

Pati David liked this post
Categories: Guest bloggers, High risk of breaking in future versions, Stock Matlab function, Toolbox, Undocumented feature
Tags: , , ,
Leave a comment

GUI formatting using HTML

As I’ve mentioned several times in the past, HTML can be used for simple formatting of GUI controls, including font colors/sizes/faces/angles. With a bit of thought, HTML (and some CSS) can also be used for non-trivial formatting, that would otherwise require the use of Java, such as text alignment, background color, and using a combination of text and icons in the GUI control’s contents.

Alignment

For example, a question that I am often asked (latest example) is whether it is possible to left/center/right align the label within a Matlab button, listbox or table. While Matlab does not (yet) have properties that control alignment in uicontrols, we can indeed use HTML for this. There’s a catch though: if we simply tried to use <div align="left">…, it will not work. No error will be generated but we will not see any visible left-alignment. The reason is that internally, the text is contained within a snugly-fitting box. Aligning anything within a tight-fitting box obviously has no effect.

To solve the problem, we need to tell Matlab (or rather, the HTML interpreter used by the underlying Java control) to widen this internal box. One way to do this is to specify the width of the div tag, which can be enormous in order to span the entire available apace (<div width="999px" align="left">…). Another method is to simulate a simple HTML table that contains a single cell that holds the text, and then tell HTML the table cell’s width:

hButton.String   = '<html><tr><td width=9999 align=left>Left-aligned';  % left-align within a button
hTable.Data{2,1} = '<html><tr><td width=9999 align=right>And right';   % right-align within a specific uitable cell
</td></tr></html></td></tr></html>

centered (default) button label   right-aligned button label

Centered (default) and right-aligned button labels

Non-default alignment of uitable cells

Non-default alignment of uitable cells

I discussed the specific aspect of uicontrol content alignment in another post last year.

Background color

The same problem (and solution) applies to background colors: if we don’t enlarge the snugly-fitting internal bounding-box, any HTML bgcolor that we specify would only be shown under the text (i.e., within the internal box’s confines). In order to display bgcolor across the entire control/cell width, we need to enlarge the internal box’s width (the align and bgcolor tags can of course be used together):
Continue reading

Categories: Medium risk of breaking in future versions, UI controls, Undocumented feature
Tags: , , ,
1 Comment