Wednesday, February 10, 2010

Brent Corrigan And Brent Everett School Crush

Write libraries MEX in C / C + +

The main elements of mex files in Matlab, written in C / C + +, are mainly four
  1. header mex.h
  2. gateway mexFunction
  3. arrays mxArray
  4. APIs function

mex.h

# include mex.h

Each mex-file written in C / C + + must have a header of mex.h include directive, so you can use the API in the form of mx * routines

Gateway mexFunction
 mexFunction (nlhs int, mxArray * plhs [], int nrhs, const mxArray * prhs 
[]) {

...
}

The routine between the gateway and Matlab mex file is called mexFunction and, essentially, is the "main" library that we are going to implement.

This routine, whose prototype is declared in mex.h said, contains the following elements:
  • nlhs mxArray is the number of outgoing (lhs - left hand side)
  • plhs is an array of pointers to the mxArray expected outputs
  • nrhs is the number input (rhs - right hand side)
  • prhs is an array of pointers to the mxArray data input, which are read-only (const)

Note that the suffix of the names of these variables relates to their usual position in a function call into Matlab. When you start executing the code contained in the mex-file, the pointers in plhs are undefined, as it is for the program explicitly define them (the compiler will not check whether that is).

mxArray

This is a data structure that manages the data of the program and C is the representation of vectors / matrices / string / cell Matlab
A
mxArray is declared as any variable
mxArray * myarray;
but it must be initialized with a mx * routines before being used (eg, mxCreateNumericArray). Note that the data in an mxArray is read / written in the typical order of Matlab, or in the column to the right, unlike C / C + + that reads in a row and down.

The API functions

The API function include, among other things, the functionality to transfer data between MEX-files and Matlab, the ability to call Matlab functions from source code in C / C + + 's access to data contained in an mxArray. The most used are related to:
  • creating arrays (mxCreateNumericArray, mxCreateCellArray, mxCreateCharArray)
  • array access (mxGetPr, mxGetPi, mxGetM, mxGetM, mxGetData, mxGetCell)
  • changes to the array (mxSetPr, mxSetPi, mxSetData, mxSetField)
  • control of an array (mxIsClass)
  • memory management (mxMalloc, mxCalloc, mxFree, mexMakeMemoryPersistent, mexAtExit, mxDestroyArray, memcpy)
  • other (mexEvalString, mexCallMATLAB, mexPrintf , mexWarnMsgTxt)

A description complete can be found in MATLAB External / API Reference Guide .

Here we present an example of a MEX-file to create an mxArray to hold the output data
 # include "mex.h" 
mexFunction void (int nlhs, mxArray * plhs [], int
nrhs, const mxArray * prhs []) {

int i, j, m, n;
double * data1, * data2;

if (nrhs! = nlhs)
mexErrMsgTxt ("The number of input and output arguments must be the same. ");

for (i = 0; i \u0026lt;nrhs; i + +)
{
/ * Find the dimensions of the data * /
m = mxGetM (prhs [i]);
n = mxGetN (prhs [i ]);

/ * Create an mxArray for the output data * /
plhs [i] = mxCreateDoubleMatrix (m, n, mxREAL)

/ * Retrieve the input data * / data1 =
mxGetPr (prhs [i]);

/ * Create a pointer to the output data * /
data2 = mxGetPr (plhs [i]);

/ * Put data in the output array * /
for (j = 0, j \u0026lt;m * n, j + + )

{data2 [j] = 2 * data1 [j];

}}}


Other examples can be found here .

Brent Corrigan And Brent Everett School Crush

Write libraries MEX in C / C + +

The main elements of mex files in Matlab, written in C / C + +, are mainly four
  1. header mex.h
  2. gateway mexFunction
  3. arrays mxArray
  4. APIs function

mex.h

# include mex.h

Each mex-file written in C / C + + must have a header of mex.h include directive, so you can use the API in the form of mx * routines

Gateway mexFunction
 mexFunction (nlhs int, mxArray * plhs [], int nrhs, const mxArray * prhs 
[]) {

...
}

The routine between the gateway and Matlab mex file is called mexFunction and, essentially, is the "main" library that we are going to implement.

This routine, whose prototype is declared in mex.h said, contains the following elements:
  • nlhs mxArray is the number of outgoing (lhs - left hand side)
  • plhs is an array of pointers to the mxArray expected outputs
  • nrhs is the number input (rhs - right hand side)
  • prhs is an array of pointers to the mxArray data input, which are read-only (const)

Note that the suffix of the names of these variables relates to their usual position in a function call into Matlab. When you start executing the code contained in the mex-file, the pointers in plhs are undefined, as it is for the program explicitly define them (the compiler will not check whether that is).

mxArray

This is a data structure that manages the data of the program and C is the representation of vectors / matrices / string / cell Matlab
A
mxArray is declared as any variable
mxArray * myarray;
but it must be initialized with a mx * routines before being used (eg, mxCreateNumericArray). Note that the data in an mxArray is read / written in the typical order of Matlab, or in the column to the right, unlike C / C + + that reads in a row and down.

The API functions

The API function include, among other things, the functionality to transfer data between MEX-files and Matlab, the ability to call Matlab functions from source code in C / C + + 's access to data contained in an mxArray. The most used are related to:
  • creating arrays (mxCreateNumericArray, mxCreateCellArray, mxCreateCharArray)
  • array access (mxGetPr, mxGetPi, mxGetM, mxGetM, mxGetData, mxGetCell)
  • changes to the array (mxSetPr, mxSetPi, mxSetData, mxSetField)
  • control of an array (mxIsClass)
  • memory management (mxMalloc, mxCalloc, mxFree, mexMakeMemoryPersistent, mexAtExit, mxDestroyArray, memcpy)
  • other (mexEvalString, mexCallMATLAB, mexPrintf , mexWarnMsgTxt)

A description complete can be found in MATLAB External / API Reference Guide .

Here we present an example of a MEX-file to create an mxArray to hold the output data
 # include "mex.h" 
mexFunction void (int nlhs, mxArray * plhs [], int
nrhs, const mxArray * prhs []) {

int i, j, m, n;
double * data1, * data2;

if (nrhs! = nlhs)
mexErrMsgTxt ("The number of input and output arguments must be the same. ");

for (i = 0; i \u0026lt;nrhs; i + +)
{
/ * Find the dimensions of the data * /
m = mxGetM (prhs [i]);
n = mxGetN (prhs [i ]);

/ * Create an mxArray for the output data * /
plhs [i] = mxCreateDoubleMatrix (m, n, mxREAL)

/ * Retrieve the input data * / data1 =
mxGetPr (prhs [i]);

/ * Create a pointer to the output data * /
data2 = mxGetPr (plhs [i]);

/ * Put data in the output array * /
for (j = 0, j \u0026lt;m * n, j + + )

{data2 [j] = 2 * data1 [j];

}}}


Other examples can be found here .

Liner On A Aluminun Boat

Book mex in matlab for windows with GNU compiler

In Matlab, MEX files (MATLAB executable) allow the execution of their code in C / C + + or Fortran directly from MATLAB as if they were built-in functions or routines. The main advantages are essentially two: the ability to use code written in C / C + + or Fortran, without the need to rewrite it as a script m-file, in addition, improved efficiency of the code (especially in loops) on the execution time.

The initialization of the build system is running mex-setup

from the Matlab prompt.
On Windows, we support a variety of compilers, like Borland and Microsoft, but here we are interested in configuring the system to use GNU tools and / or open-source, which are not present in native system. We can opt for MinGW or Cygwin for , we preferred the first.
Once you install the compiler with all the libraries, checked the environment variables are correctly configured, the configuration of the gaming mex pass through a convenient utility gnumex .




This utility is going to create the script that is invoked for each mexopts.bat compilation, invoking, with the right parameters, the compiler gcc.
If all goes well, it should be possible to compile a sample code provided with Matlab:
yprime.c
mex functions yprime.dll implemented in the new library, generated from the compilation of C code, may be invoked as the usual functions of Matlab:
yprime (1,1:4) ans =



2.0000 8.9685 4.0000

-1.0947

More information:

Liner On A Aluminun Boat

Book mex in matlab for windows with GNU compiler

In Matlab, MEX files (MATLAB executable) allow the execution of their code in C / C + + or Fortran directly from MATLAB as if they were built-in functions or routines. The main advantages are essentially two: the ability to use code written in C / C + + or Fortran, without the need to rewrite it as a script m-file, in addition, improved efficiency of the code (especially in loops) on the execution time.

The initialization of the build system is running mex-setup

from the Matlab prompt.
On Windows, we support a variety of compilers, like Borland and Microsoft, but here we are interested in configuring the system to use GNU tools and / or open-source, which are not present in native system. We can opt for MinGW or Cygwin for , we preferred the first.
Once you install the compiler with all the libraries, checked the environment variables are correctly configured, the configuration of the gaming mex pass through a convenient utility gnumex .




This utility is going to create the script that is invoked for each mexopts.bat compilation, invoking, with the right parameters, the compiler gcc.
If all goes well, it should be possible to compile a sample code provided with Matlab:
yprime.c
mex functions yprime.dll implemented in the new library, generated from the compilation of C code, may be invoked as the usual functions of Matlab:
yprime (1,1:4) ans =



2.0000 8.9685 4.0000

-1.0947

More information:

Thursday, February 4, 2010

Scanning Freqs Australia

frame blended with nautilus-script

The following script modifies a selected image with another to produce a frame smoked transparent a few pixels.

# / bin / sh # This script
change the input image by adding a fuzzy frame
# Dependencies: imagemagick, bc

# # 2010 - ver 0.1 - bleish.wordpress.com

PATH = `pwd` [-n "$ PATH"] & & cd "$ PATH"
if [$ # - eq 0];
then zenity - title = "PDFJoin" - error - title = "Warning" \\
- text = "Select a file."
exit 1
fi
h = `identify-format '% h'" $ 1 "`
w = `identify-format '% w'" $ 1 "`
h1 = `echo $ h-5 xc:-draw "$ string"-blur 30x3-denied "$ MASK.png"
convert "$ TEMPFILE.png" "$ MASK.png" + matte-compose-composite CopyOpacity "c $ 1.png"
rm-f "$ MASK.png"
rm-f "$ TEMPFILE.png"
rm-f "$ tempfile"
rm-f "$ MASK"


E 'useful to include the script in the nautilus-scripts in ~ /. gnome2/nautilus-scripts
represented in the images below you can see the result of running the script.





Scanning Freqs Australia

frame blended with nautilus-script

The following script modifies a selected image with another to produce a frame smoked transparent a few pixels.

# / bin / sh # This script
change the input image by adding a fuzzy frame
# Dependencies: imagemagick, bc

# # 2010 - ver 0.1 - bleish.wordpress.com

PATH = `pwd` [-n "$ PATH"] & & cd "$ PATH"
if [$ # - eq 0];
then zenity - title = "PDFJoin" - error - title = "Warning" \\
- text = "Select a file."
exit 1
fi
h = `identify-format '% h'" $ 1 "`
w = `identify-format '% w'" $ 1 "`
h1 = `echo $ h-5 xc:-draw "$ string"-blur 30x3-denied "$ MASK.png"
convert "$ TEMPFILE.png" "$ MASK.png" + matte-compose-composite CopyOpacity "c $ 1.png"
rm-f "$ MASK.png"
rm-f "$ TEMPFILE.png"
rm-f "$ tempfile"
rm-f "$ MASK"


E 'useful to include the script in the nautilus-scripts in ~ /. gnome2/nautilus-scripts
represented in the images below you can see the result of running the script.





Hot Cheetos And Stomaches

gnome-screenshot and snapshots partial desktop

gnome-screenshot is useful to capture a snapshot of the screen. On Linux systems (and ubuntu:-P) are configured by default the ability to capture a screenshot of the entire screen or active window, use the combination Alt + id keys Stamp and Stamp. Should the opportunity arise also from the console, with controls, respectively
gnome-screenshot-w
addition to these options, are interesting also use the delay required (- delay = seconds), the ability to add effects like shadows or edges (- = border effect - effect = shadow), and finally, the ability to display a convenient GUI to indicate these and other options before making the snapshot. However, the most attractive option is that it can indicate the region to capture the desktop in order to avoid annoying scraps and photo editing after capture:

gnome-screenshot-a This can be a custom command to be inserted between shortcuts keyboard, perhaps associated with the pressure of the key combination Ctrl + Print Screen. See the picture above for more details.


Hot Cheetos And Stomaches

gnome-screenshot and snapshots partial desktop

gnome-screenshot is useful to capture a snapshot of the screen. On Linux systems (and ubuntu:-P) are configured by default the ability to capture a screenshot of the entire screen or active window, use the combination Alt + id keys Stamp and Stamp. Should the opportunity arise also from the console, with controls, respectively
gnome-screenshot-w
addition to these options, are interesting also use the delay required (- delay = seconds), the ability to add effects like shadows or edges (- = border effect - effect = shadow), and finally, the ability to display a convenient GUI to indicate these and other options before making the snapshot. However, the most attractive option is that it can indicate the region to capture the desktop in order to avoid annoying scraps and photo editing after capture:

gnome-screenshot-a This can be a custom command to be inserted between shortcuts keyboard, perhaps associated with the pressure of the key combination Ctrl + Print Screen. See the picture above for more details.