Sunday, August 17, 2014

MATLAB SFTP with WinSCP

One of the ways to transfer files using SFTP in MATLAB (sort of) is simply to do it in an external tool (e.g., WinSCP). Assuming the tool supports scripting (WinSCP's scripting), you can prepare the scripts first and simply call the tool using the ! command with the path to the script file. A few thoughts: 1. put it in a timer function to automate the transfer 2. dynamically generate the script so that actions can vary in each session 3. wonder if the session can be maintained in which case we could provide some sort of interactivity in MATLAB's command window.

Saturday, May 3, 2014

MATLAB MySQL query datetime column type

When you do a SELECT * in MySQL query from MATLAB, you would expect all the entries in the table to be returned.

Apparently, there are cases where it will not return everything. (Matlab R2013a, MySQL 5.5.32)

It seems that if you have '0000-00-00 00:00:00' in the datetime field of a row, which is the zero value of the datetime type, the row will not be returned even if you do the select all query.

However, if you are querying other columns (besides the datatime column), the row that has the zero value datetime will be returned.



Tuesday, April 15, 2014

moving things to github

I am in the process of moving some of the source code from the past postings into github. It is easier to share, easier to maintain, and easier to get feedback (if any).

https://github.com/weishang

As a side-note/rant, if you look at the source control options for Matlab, I don't know, it feels lacking. With all the options available nowadays (2014), Matlab supports MS visual sourcesafe, whose final version is 2005.


Saturday, February 1, 2014

Multi-'screen' MATLAB GUI

Once again, I had little time cleaning up the post so read at your own risk. :-) 

Why bother?


First and foremost, the multi-screen GUI I am talking about is much like a Single Page Application (SPA) in the context of web application. Everything you see in the GUI can change entirely as you 'navigate' from "screen" to "screen". An example would be an application that has various stages to it, as the user goes from stage to stage, only the relevant information/controls will show on the GUI. Of course, you can always just slap everything on the GUI without considering splitting them into "screens", but you only have so much space on the GUI and every bit of information that shouldn't be there is wasting the UI space.

<begin digression>
Also, one can also implement the application using multiple GUIs instead of multiple screens. Such approach is more appropriate in the case where the different GUIs have to be shown at the same time, but there are distinct features about each GUI so it doesn’t really make sense to put them all in the same GUI, also, reusability is another issue. But that’s a different topic altogether.
<end digression>

Enough background. Below is how.

First of all, there is no such feature (multiple-screen GUI) in Matlab, but there is a little trick we can use to make it appear so, and that is with the use of 'uipanel'.

The concept is fairly simple, assuming you have already got a design in mind, i.e., you are clear about what uicontrols go into to what uipanel, all you need to do is have them populated in the right panels, subsequently, we show and hide the panels as we see fit. Note that the panels should have been resized at this point so they overlap completely, and at any given time, only one panel should be shown (Visible = 'on'), while others are hidden (isVisible = 'off'). (I don't understand why 'on'/'off' are used instead of true/false or 1/0.)

Now, I would strongly recommended creating everything programmatically instead of relying on Matlab’s GUIDE, as the panel will need to be resized, moved around, which is impossible to do in GUIDE. You also need to pay special attention to the unit setting for all the uicontrols when you are doing this, if there is any mis-matches or invalid values, then the uicontrols may not show up, or when you resize the GUI, the uicontrols in a panel may all go crazy.
Below is the link to a fairly simple demo that shows the multi-screen in action of the application. Three buttons to show one of the three panels (much like the tab effect if you just position them in a better way).
https://github.com/weishang/matlab-multiScreen

What else?


The trick described in this post is using overlapping panels as screens and show/hide the panels as you desired. Here’s what else you can do with this trick.
  • A demo application which goes from one screen to the next, much like a slide show. With the help of the timer object (may find this post useful). 
  • A GUI with the ‘tab’ effect 
  • A fully blown single page application 
  • ...