Proficient VC and MATLAB joint programming (VI)

Source: Internet
Author: User
Tags include root directory

Matlab c\c++ function Library is an important part of the extension function of Matlab, contains a lot of MATLAB functions rewritten with c\c++ language, including elementary mathematics function, linear algebra function, matrix operation function, numerical calculation function, special mathematical function, polynomial function, Interpolation functions, users can call these functions in their own c\c++ programs to achieve complex matrix computing functions, thereby reducing the workload of programming, it needs to be explained that C function library and C + + function library is two different function libraries.

Installation is required before use:

In the MATLAB command window, enter:

Mbuild-setup

Follow the prompts to select the VC compiler, completed in the MATLAB command Window input:

Mex-setup

Also select the VC compiler, the compiler to complete the installation and configuration.

Firstly, we introduce the library functions of C function library and C functions library under this directory: Matlab root directory: \extern\lib

Here is a matlab with a use of C function library example (all using the C function example in: Matlab root directory \extern\examples\cmath):* EX1.C
*
* Copyright (c) 1995-1999 by the MathWorks, Inc. All Rights Reserved.
*/
/* $Revision: 1.6 $/*
#include <stdio.h>
#include <stdlib.h>/* Used for exit_success * *
#include <string.h>
#include "Matlab.h"/*matlab.h as the header file for the C Math function library
Static double real_data[] = {1, 2, 3, 4, 5, 6};
Static double cplx_data[] = {7, 8, 9, 10, 11, 12};
int main ()
{
/* Declare two Mxarray matrix variable and assign initial value to NULL * *
Mxarray *mat0 = NULL;
Mxarray *MAT1 = NULL;
/* Use automatic memory management * *
Mlfenternewcontext (0, 0);
/* Create matrix MAT0,MAT1 and assign value * *
Mlfassign (&mat0, Mlfdoublematrix (2, 3, Real_data, NULL));/* This matrix is a 2*3 matrix
Mlfassign (&AMP;MAT1, Mlfdoublematrix (3, 2, Real_data, Cplx_data));/* The Matrix is a 2*3 matrix and is a complex matrix
/* Print Matrix * *
Mlfprintmatrix (MAT0);
Mlfprintmatrix (MAT1);
/* Release the memory of the matrix * *
Mxdestroyarray (MAT0);
Mxdestroyarray (MAT1);
/* Disable automatic memory management * *
Mlfrestorepreviouscontext (0, 0);
return (exit_success);
}

If there is an image, please indicate the image index number in the image file, such as "Myappimg1.gif", "myappimg2.gif", and so on, in the image display below annotated image description:

Figure A program running results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.