PDA

View Full Version : CalculusMatlab: exchanging arbitrary data with MATLAB


Daniel Lichau
18th March 2008, 16:41
The Avizo module CalculusMatlab allows executing MATLAB scripts. Uniform fields can be connected as inputs. These are made available in the MATLAB workspace as script variables. Results are returned in the same data objects.

Here is a possible way to exchange arbitrary data between Avizo and MATLAB, involving some TCL script commands.

In this example, data are point coordinates from a landmark or vertex set "landmark.am":

Create an Arithmetic module via top menu Create/Data/Arithmetic, and press apply button, just to create a uniform field with float values ("Result")


You can use a 3 x N x 1 lattice to store N coordinates x,y,z. You could have defined lattice resolution in Arithmetic module. Otherwise use the TCL command "crop":
Result crop 0 2 0 [landmark.am getNumPoints] 0 0
(Usage: crop [-auto threshold | imin imax jmin jmax kmin kmax [value]])



Retrieve point coordinates and store them in lattice data:
for {set pointIndex 0 } { $pointIndex < [landmarks.am getNumPoints] } {incr $pointIndex }
for {set coordIndex 0 } { $coordIndex < 3 } { incr coordIndex} {
set coordValue [landmarks.am getPoint $coordIndex ]
Result setValue $coordIndex $pointIndex 0 $coordValue

}

}

Notice that you can use such command split in mutiple lines only in a script file (.hx or .scro). To enter the command sequence above in the console, use a single line.


Connect CalculusMatlab module to Result: data are then available in MATLAB script. See CalculusMatlab help for details.


You can retrieve result data from MATLAB via TCL:
Result getValue <i> <j> <k>



Credits

Daniel Lichau

forum_admin
20th March 2008, 15:36
Very interesting Daniel,
Thanks for this contribution.
Can you add a sample script file or hx file to illustrate that ?