Pass Arrays of Strings

Passing arrays of strings adds a complication to the example Pass Strings. Because MATLAB® stores elements of a matrix by column instead of by row, the size of the string array must be correctly defined in the Fortran MEX-file. The key point is that the row and column sizes as defined in MATLAB must be reversed in the Fortran MEX-file. So, when returning to MATLAB, the output matrix must be transposed.

This example places a string array/character matrix into MATLAB as output arguments rather than placing it directly into the workspace.

To build this example, at the command prompt type:

mex passstr.F



to create the 5-by-15 mystring matrix. You need to do some further manipulation. The original string matrix is 5-by-15. Because of the way MATLAB reads and orients elements in matrices, the size of the matrix must be defined as M=15 and N=5 in the MEX-file. After the matrix is put into MATLAB, the matrix must be transposed. The program passstr.F illustrates how to pass a character matrix. To see the code passstr.F, open the fileopen the file in MATLAB Editor.


ans =

The Scientific 
   by TMW, Inc.
Was this topic helpful?