Mathworks.com – Undocumented Matlab https://undocumentedmatlab.com/blog_old Charting Matlab's unsupported hidden underbelly Thu, 27 Oct 2022 10:42:32 +0000 en-US hourly 1 https://wordpress.org/?v=4.4.1 Tips for accelerating Matlab performancehttps://undocumentedmatlab.com/blog_old/tips-for-accelerating-matlab-performance https://undocumentedmatlab.com/blog_old/tips-for-accelerating-matlab-performance#comments Thu, 05 Oct 2017 18:25:06 +0000 https://undocumentedmatlab.com/?p=7099 Related posts:
  1. Performance: scatter vs. line In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...
  2. Plot LimInclude properties The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....
  3. Plot performance Undocumented inner plot mechanisms can significantly improve plotting performance ...
  4. Performance: accessing handle properties Handle object property access (get/set) performance can be significantly improved using dot-notation. ...
]]>
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). You can read the full detailed technical article here.

Crustal dynamics visualization GUI

Crustal dynamics visualization GUI

Featuring an article on the official newsletter by a non-MathWorker is rare. Doing this with someone like myself who has a reputation for undocumented aspects, and a consultancy business that potentially competes with theirs, is certainly not obvious. I take this to be a sign that despite the possible drawbacks of publishing my article, MathWorks felt that it provided enough value to the Matlab user community to merit the risk. I applaud MathWorks for this, and thank them for the opportunity of being featured in their official newsletter and conferences. I do not take it for granted in the least.

The newsletter article provides multiple ideas of improving the run-time performance for file I/O and graphics. Many additional techniques for improving Matlab’s performance can be found under the Performance tag in this blog, as well as in my book “Accelerating MATLAB Performance” (CRC Press, 2014, ISBN 978-1482211290).

I am offering a couple of webinars about various ways to improve Matlab’s run-time performance:

Both the webinar videos and their corresponding slide-decks are available for download. The webinars content is based on onsite training courses that I presented at multiple client locations (details).

 Email me if you would like additional information on the webinars or my consulting, or to inquire regarding an onsite training course.

]]>
https://undocumentedmatlab.com/blog_old/tips-for-accelerating-matlab-performance/feed 2
MathWorks blogs facelifthttps://undocumentedmatlab.com/blog_old/mathworks-blogs-facelift https://undocumentedmatlab.com/blog_old/mathworks-blogs-facelift#comments Sun, 12 Jan 2014 21:01:11 +0000 https://undocumentedmatlab.com/?p=4573 Related posts:
  1. Changes in the online doc URLs Matlab release R2012b has broken a vast number of links to its online documentation pages. ...
  2. Removing user preferences from deployed apps An unsupported MathWorks Technical Solution explains how to remove private information from deployed (compiled) matlab applications. ...
  3. Matlab-Java interface using a static control The switchyard function design pattern can be very useful when setting Matlab callbacks to Java GUI controls. This article explains why and how....
  4. HG2 update HG2 appears to be nearing release. It is now a stable mature system. ...
]]>
For those of you who have not noticed, MathWorks has made a very nice facelift to its official blogs section on Matlab Central (there are also some unofficial internal blogs, but they are unfortunately not publicly accessible).

If you have not done so already, I encourage you to browse the available blogs and subscribe – some very interesting content has accumulated there, and continues to be added a few times each month. I follow these blogs closely, and have learned quite a bit from them over the years.

No official announcement has been released yet AFAIK. However, I expect (at the very least) a post about this in the next few days in the “Matlab Spoken Here” blog (formerly the Desktop or Community blog). If and when it is posted, I encourage you to post a comment there, letting MathWorks know what you think of the new look-&-feel. Until then, this remains an undocumented feature [ he he :-) ] and you can leave your comments below…

Don’t let this stop you from subscribing to this blog – simply click the RSS button or subscription link at the top of this webpage to get the latest undocumented article delivered to you via email or reader, once a week. And guess what? it’s completely free… In the meantime, enjoy the following earth-shattering archaeological find that I found in some online archive:

Prehistorical Matlab blog from Draa River

Prehistorical Matlab blog from Draa River
note the incomplete formula (left) and the simplistic plot figure (right)

Addendum April 4, 2014: It took some time but the anticipated official MathWorks blog post about this has finally arrived today!

]]>
https://undocumentedmatlab.com/blog_old/mathworks-blogs-facelift/feed 1
Removing user preferences from deployed appshttps://undocumentedmatlab.com/blog_old/removing-user-preferences-from-deployed-apps https://undocumentedmatlab.com/blog_old/removing-user-preferences-from-deployed-apps#respond Wed, 07 Nov 2012 18:00:19 +0000 https://undocumentedmatlab.com/?p=3302 Related posts:
  1. Changes in the online doc URLs Matlab release R2012b has broken a vast number of links to its online documentation pages. ...
  2. Matlab compiler bug and workaround Both the Matlab compiler and the publish function have errors when parsing block-comments in Matlab m-code. ...
  3. Javacomponent background color This article explains how to align Java component background color with a Matlab color....
  4. Recovering previous editor state Recovering the previous state of the Matlab editor and its loaded documents is possible using a built-in backup config file. ...
]]>
Every now and then I stumble upon a MathWorks technical note/solution that uses undocumented features. I already posted a few of these here (e.g., this one for the continuous slider movement issue, and this one for the figure maximization/minimization issue). In fact, you may be surprised to know that there are dozens of other official technical notes, solutions and articles that use undocumented/unsupported Matlab functionality. Yummy!

Of the numerous official resources containing unofficial information (I can’t help but smile), do you have a personal favorite? If so, please post a link in a comment below, with a short description of what it is about.

Today, I show one such technical solution (http://www.mathworks.com/support/solutions/en/data/1-1UOGW7/) that solves a privacy issue in deployed (compiled) Matlab applications. IMHO, the privacy issue is generally harmless, but users can judge by themselves. Obviously, if someone is stupid enough to store real secret information in the Matlab preferences, then the privacy issue could become more important.

The solution refers to Matlab release 7.1 (R14SP3), but is also relevant for later releases. I will let the text speak for itself:

When I execute an application compiled using MATLAB Compiler 4.3 (R14SP3), how can I prevent personal information such as my MATLAB preferences information from being extracted?

Problem Description:

I have compiled an application ‘test’ using MATLAB Compiler 4.3 (R14SP3). Upon execution I noticed that a new folder gets created in the ‘test_mcr’ folder. This folder is named ‘test_‘.

Opening this folder revealed that some of the files were stored in my MATLAB preferences directory, including my MATLAB preferences file.

I want to know if there is any way to avoid the creation of this directory when my application executes.

Solution:

It is not possible to avoid having MATLAB Compiler include the preferences directory in each compiled application. The Compiler includes the user’s preference information because the application may rely on it. There are two possible workarounds:

1) On UNIX, use SETENV and the ! operator to compile. For example:

!setenv MATLAB_PREFDIR /tmp/emptydir;
mcc -Nmgv test

On Windows, open a DOS command window and execute

set -- USERPROFILE = C:\Temp\emptydir

Start MATLAB from this DOS prompt (to use the appropriate environment variable in the MATLAB session) and execute the MCC command at the MATLAB command prompt.

Note: If you are using MATLAB Compiler 4.4 (R2006a) you can also use the SETENV function at the MATLAB command prompt

setenv('-- USERPROFILE','C:\Temp\emptydir');
mcc -Nmgv test

This temporarily sets the preference directory to /tmp/emptydir or C:\Temp\emptydir, and the compiled application will therefore only have the default settings (or the preference directory settings from your installation of MATLAB 7.0.4 (R14SP2)).

2) Move the contents of the preference directory, or rename the directory, before compilation, and restore afterwards. To do this on Windows, for example, execute the following command to compile the function test.m:

mymcc -m test.m

The code of the function mymcc is:

function mymcc(varargin)
% MYMCC does the same as MCC. The only difference is that the created
% application doesn't contain information of the MATLAB 
% prefdir anymore.
%
% For the description of possible options please look at the help of 
% the command MCC.
 
command = 'mcc ';
for i = 1 : length(varargin)
   command = [command,varargin{i},' '];
end
 
a = prefdir;
b = regexp(a,'\','start');
c = a(b(end)+1:end);
 
p = cd;
cd(prefdir)
cd ..
!md tmp
cd(prefdir)
!move * ../tmp
cd(p)
 
% Because of the displacement MATLAB cannot access the saved preferences
% and that's why you have to indicate each time, which compiler shall be used.
try
   eval(command);
catch
   warning('WarnTests:Warning', ...
           'Calling mcc causes Error. Please check your input arguments.\n No file was compiled ...\n')
end
 
cd(prefdir)
cd ..
cd tmp
eval(['!move * ../',c]);
cd ..
!rmdir tmp
cd(p);

A similar function could also be written for the UNIX platform.

Note that the above workaround is not officially supported by MathWorks.

Why are my preference files included in my stand-alone application created with MATLAB Compiler 4.9 (R2008b)?

Problem Description:
If I look in the cache folder that my compiled application creates, I can see that the .matlab folder contains my preference files with my last development activities in plain text. The files are: cwdhistory.m, history.m, matlab.prf, MATLAB_Editor_State.xml, etc. How can I avoid the inclusion of these files in the stand-alone application?

Solution:
The stand-alone does not include your preference files. You can see the preference files in the cache folder because you are running the stand-alone in your development environment. At runtime, the stand-alone determines those preferences from a local MATLAB installation and copies them to the cache folder for it’s own use. If you run your stand-alone application on a machine without a MATLAB installation, you will see that the cache folder does not contain your preference files.

]]>
https://undocumentedmatlab.com/blog_old/removing-user-preferences-from-deployed-apps/feed 0
Changes in the online doc URLshttps://undocumentedmatlab.com/blog_old/changes-in-the-online-doc-urls https://undocumentedmatlab.com/blog_old/changes-in-the-online-doc-urls#comments Wed, 10 Oct 2012 18:00:57 +0000 https://undocumentedmatlab.com/?p=3224 Related posts:
  1. Removing user preferences from deployed apps An unsupported MathWorks Technical Solution explains how to remove private information from deployed (compiled) matlab applications. ...
  2. Matrix processing performance Matrix operations performance is affected by internal subscriptions in a counter-intuitive way....
  3. Undocumented scatter plot jitter Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...
  4. ishghandle’s undocumented input parameter The built-in function ishghandle accepts a second input argument with the expected handle type....
]]>
Along with the extensive facelift done to Matlab’s documentation system in R2012b, one important aspect has gone largely unnoticed. Apparently, in the interest of making the doc pages more SEO-friendly, MathWorks have modified the online documentation URLs from something that looks like http://www.mathworks.com/help/techdoc/creating_guis/f16-999606.html to http://www.mathworks.com/help/matlab/creating_guis/writing-code-for-callbacks.html.

The problem

This change in itself is actually a good idea, but what is absolutely disastrous (IMHO) is the fact that MathWorks have not bothered to link all the old URLs to the new ones. Most serious websites that have tons of links floating around for a decade or two, as in this case, take the trouble to automatically redirect old URLs to the new ones in the server side. This was the case, for example, when Oracle took over Sun a couple of years ago and redirected the Java links. So did Microsoft in their online MSDN. Neither Oracle nor Microsoft redirected all the URLs perfectly, but they made a pretty good effort. Not in Matlab’s case, unfortunately.

It seems that only the basic function reference pages have been redirected, not any of the other doc pages. Tons of links, many of them in MathWorks webpages themselves, are now broken and lead to a generic “page not found” webpage. This includes many thousands of links referenced by loyal community users in response to queries in the Matlab CSSM newsgroup (in the past ~15 years) and MathWork’s own Answers forum (past 1.5 years), not to mention numerous references in books, reports, websites and other resources. These links are now broken. Users who use them will end up in page-not-found. How user-friendly would this be for them? How likely do you think they would use the newsgroup/forum again, as opposed to flooding MathWorks customer support with simple questions that have already been answered online, only to be rendered unusable by an SEO fix that should have been fully transparent?! How likely do you think that loyal CSSM/Answers contributors would post MathWorks links again?! This is about as self-defeating a release as I have seen in a very long time.

In the past, I have highlighted changes to the online documentation center that I found useful. These included the addition of historical documentation archives, and the plot gallery. But today I must say that IMHO the latest change to the doc center should never have gone live, and I fail to understand how it could ever have passed internal QA. Furthermore, I cannot understand why this is still not fixed, a month after the official release.

I don’t believe that I have ever used such strong language in the 3.5 years that this blog has been live, and I do this very reluctantly now. Hopefully my call for action will be heeded (soon!).

So what can be done?

MathWorks can and should correct this problem by adding the server-side redirects, which is typically accompanied by an HTTP 301 Moved Permanently response to the requesting browser. In fact, doing this is also good for SEO, since all the tons of old links will be counted by search engines as directing to the new pages, thereby adding incoming page-rank “juice” to them. Here’s Google’s advise on this matter.

Doing these redirects does not require a Matlab release and can be done immediately and incrementally. Granted it’s not a simple task, given the huge number of URLs involved, but the sooner MathWorks start, the faster they’ll finish. Frankly, they should have thought about it in advance… I have a hunch that the servers’ HTTP 404 (Page Not Found) list has exploded since the latest release. I would suggest going through this list, sorted down by number of occurrences, so that the most frequently-accessed webpages are fixed first.

Until the URLs are restored or redirected, we can try the following workaround:

  1. First try the URL directly (e.g., http://www.mathworks.com/help/techdoc/creating_guis/f16-999606.html) – who knows, maybe it will work by the time you try using it…
  2. If the URL that doesn’t work, try to add releases/R2012a/ following the “help/” term in the URL. In our example: http://www.mathworks.com/help/releases/R2012a/techdoc/creating_guis/f16-999606.html. If successful, jump to step #4 below.
  3. If the URL is still not found, enter it into the Way-Back Machine in the following format: http://wayback.archive.org/web/*/<URL>. For example: http://wayback.archive.org/web/*/http://www.mathworks.com/help/techdoc/creating_guis/f16-999606.html
    If we’re lucky, the Way-Back archive has at least one archived copy of the requested webpage. This also happens to be the case in this specific instance:
    Way-Back Machine's archived versions of a webpage

    Way-Back Machine's archived versions of a webpage

    Click the highlighted date (when an archive copy was taken) to see our requested webpage in all its past glory. We are not assured that it is the latest version of the webpage, but this is ok for now.

  4. If all you need is to read the contents of the doc page, then you can stop here. But if you also wish to get the new URL (in its R2012b SEO format), then read on:
  5. Copy a long distinctive sentence from the webpage content in to the clipboard; paste into Google within “” (quotation marks) and add the term “site:mathworks.com”. In our case, let’s take “A callback is a function that you write and associate with a specific component in the GUI“. Here is the corresponding Google query: site:mathworks.com “A callback is a function that you write and associate with a specific component in the GUI”.
  6. If we are lucky again, Google should turn up the new webpage and by navigating there we should (finally!) get the new URL. In this case, the requested URL is the top answer: http://www.mathworks.com/help/matlab/creating_guis/writing-code-for-callbacks.html
  7. Sometimes Google fails to find the sentence in the Mathworks.com website. This can be due to text changes that MathWorks do in their doc pages from time to time. Don’t give up – try a different sentence from the archived webpage, maybe it will show up instead. You can also try to enter the page title as the distinctive sentence. There is a good chance that at least one of these will work. In our specific example, MathWorks changed the title from “Writing Code for Callbacks” to “Write Code for Callbacks” in R2011b (after the Way-Back Machine archived the page). Luckily, the title query still manages to find the new page in this specific case (good ol’ dependable Google!).
  8. Any of the above may fail, typically because the Way-Back archive did not archive the specific page we need, or because MathWorks changed the page contents too much. In such a case, too bad for us… In this case, I suggest you email MathWorks to ask for the new URL.

Followups

Vociferous complaints over the new documentation system in R2012a have been heard loud and clear at MathWorks. Wendy Fullam, Matlab’s documentation product manager, has made a point to make it clear that MathWorks is not ignoring these out-of-the-ordinary complaints and will indeed improve the documentation accordingly. Wendy also responded to my SEO complaint, saying that they will indeed try to fix the URL redirects:

However some pages have not been redirected for various reasons. Given feedback like this, we are looking into creating more redirects as soon as possible.

I’m holding my fingers that they will indeed fix this issue, not just for some URLs (as the quote above seems to indicate) but for all of them. MathWorks’ quick and serious response to the complaints on R2012b make me optimistic that there is indeed a good chance that this will be resolved soon. I’ll be following up on this issue in the upcoming months, and will be most happy to post an update here if and when this issue is fully resolved as it should be, on the MathWorks server side.

Addendum Oct 14, 2012 (that was quick!): Wendy Fullam has posted the following comment on the relevant CSSM thread (snipped for brevity):

In response to customer feedback, MathWorks is deploying an additional 700 redirects for documentation URLs.

When combined with the redirects already deployed (for reference pages, landing pages, installation sections, and release notes), we will be redirecting roughly 70% of R2012a documentation URLs to updated page locations.

We will also continue to monitor “page not found” reports, and establish additional redirects as needed.

Additionally, I’d like to note that the discussion has been incredibly insightful in helping the documentation team establish future direction. Customers noted that the doc appears to have undergone a change in organization and have speculated on the motivation. While SEO was part of our motivation (we think it’s a big step in having URLs provide an indication of page focus), we are also working towards serving up information to support common customer workflows. … I want to encourage you all to continue to share experiences and requests for missing information, so our documentation team can continue to expand and improve our content.

Addendum Nov 19, 2012: Looks like the http://www.mathworks.com/help/techdoc/creating_guis/f16-999606.html link is alive again, or rather redirected to the new location which is great. I hope this means that the redirection effort mentioned by Wendy above has finally occured. Thanks Wendy (and all the nameless others behind the scenes)!

]]>
https://undocumentedmatlab.com/blog_old/changes-in-the-online-doc-urls/feed 6