Computing 2012

Useful MATLAB miscellany

This page contains a variety of MATLAB trivia/commands which are likely to be useful to members of the Experimental Neuroimaging Group but may also be of use to other people. There's no real formal structure to the page, just commands that have come up amongst us and may be useful for others.

Manipulating each row in a matrix using a different value

Consider these two matrices:

>> a = [1 2 3 4 5; 6 7 8 9 10]
a =
     1     2     3     4     5
     6     7     8     9    10
>> b = [1; 2]
b =
     1
     2
>> c = a*b

What I want is to multiply each value in the first row of a by the first value in b. The logical approach may be to try a simple multiplication. Unfortunately, MATLAB doesn't follow:

>> c = a*b
??? Error using ==> mtimes
Inner matrix dimensions must agree.

This could be solved using a short loop but a better approach is to use bsxfun which is an element by element array manipulation tool:

>> c = bsxfun(@times,a,b)
c =
     1     2     3     4     5
    12    14    16    18    20

This gives the desired result and is very useful for a variety of biological functions e.g. multiplying a series of datasets by individual scaling factors based on a standard. Many functions can be used here as well e.g. @plus, @minus and so on.

Read more...First published on 26th November 2012 and last modified on 30th November 2012.


Reducing the size of a VirtualBox hard drive file

VirtualBox hard drive files (*.vdi) can be created as dynamic files which expand to the requirement of the guest operating system. This is wonderful but often they do not represent the smallest size they could be; indeed they are often quite large with respect to their nominal contents.

To solve this, they need to be compacted. This is a relatively simple procedure and allows for the file size on the host machine to decrease to match the minimum requirements of the guest machine. In my situation, I have a Linux host and a Windows guest. To compact the vdi file, follow these three steps:

Read more...Published on 13th February 2012.


Mounting file systems over two SSH hops

When working with files on a remote linux system it is useful to be able to mount whole directories as part of the local file system. This means that you can work with the remote data as if it on the local system. This is much more seamless and convenient that fetching individual files to work with using SCP or SFTP or similar.

Fortunately, there exists a neat way to do this using sshfs. There are already a great many tutorials on how to set up sshfs as well as the sshfs manual page so I won't repeat unnecessary details here. Instead I want to concentrate on my problem getting sshfs working across two ssh connections simultaneously.

Read more...Published on 21st January 2012.


< Newer articles | Older articles >