matlab与vc集成开发传动比

matlab与vc集成开发传动比,第1张

的计算

1、建立Matlab的GUI界面,编写程序完成传动比的计算。

2、编写VC程序,与Matlab的GUI界面进行数据交换。野碰

3、调用Matlab编写的函数计裤瞎算传动比,将结果返回给VC程序。

4、VC程序根据传动比的计算结果,将其显颂纯谈示到Matlab的GUI界面上。

VC只能调用matlab的引擎,然后使毁渣渗用纤脊matlab引擎画图,实质上是用vc给matlab命令然后让matlab自己去执行

lz问题解决方法:

1.

调用引擎,让matlab自己去画图显示

2.

调用引擎,用matlab进行拟合,然后梁棚自己用vc来画图像

使用mex命令。但是转化函数的编写规则有一定的要求。

在matlab的安装文件\extern\examples\mex有一些程序编写实例,可以仔细参考一下。以其中的yprime.c函数为例。

在matlab命令窗口执行:

mex

yprime.c

会生成一个可执行的文件,可以不芦洞配管他。(注意文件的路径)

然后就可以在命令窗口直接使用yprime(a%参数)函数了。与一般的函数使用没有多大差别。下面贴一下c文件编写:(在\extern\陪指examples\mex中有很多)

/*=================================================================

*

*

YPRIME.C

Sample

.MEX

file

corresponding

to

YPRIME.M

*

Solves

simple

3

body

orbit

problem

*

*

The

calling

syntax

is:

*

*

[yp]

=

yprime(t,

y)

*

*

You

may

also

want

to

look

at

the

corresponding

M-code,

yprime.m.

*

*

This

is

a

MEX-file

for

MATLAB.

*

Copyright

1984-2006

The

MathWorks,

Inc.

*

*=================================================================*/

/*

$Revision:

1.10.6.4

$

*/

#include

<math.h>

#include

"mex.h"

/*

Input

Arguments

*/

#define

T_IN

prhs[0]

#define

Y_IN

prhs[1]

/*

Output

Arguments

*/

#define

YP_OUT

plhs[0]

#if

!defined(MAX)

#define

MAX(A,

B)

((A)

>

(B)

?

(A)

:

(B))

#endif

#if

!defined(MIN)

#define

MIN(A,

B)

((A)

<

(B)

?

(A)

:

(B))

#endif

static

double

mu

=

1/82.45

static

double

mus

=

1

-

1/82.45

static

void

yprime(

double

yp[],

double

*t,

double

y[]

)

{

double

r1,r2

(void)

t

/*

unused

parameter

*/

r1

=

sqrt((y[0]+mu)*(y[0]+mu)

+

y[2]*y[2])

r2

=

sqrt((y[0]-mus)*(y[0]-mus)

+

y[2]*y[2])

/*

Print

warning

if

dividing

by

zero.

*/

if

(r1

==

0.0

||

r2

==

0.0

){

mexWarnMsgTxt("Division

by

zero!\n")

}

yp[0]

=

y[1]

yp[1]

=

2*y[3]+y[0]-mus*(y[0]+mu)/(r1*r1*r1)-mu*(y[0]-mus)/(r2*r2*r2)

yp[2]

=

y[3]

yp[3]

=

-2*y[1]

+

y[2]

-

mus*y[2]/(r1*r1*r1)

-

mu*y[2]/(r2*r2*r2)

return

}

void

mexFunction(

int

nlhs,

mxArray

*plhs[],

int

nrhs,

const

mxArray*prhs[]

)

{

double

*yp

double

*t,*y

mwSize

m,n

/*

Check

for

proper

number

of

arguments

*/

if

(nrhs

!=

2)

{

mexErrMsgTxt("Two

input

arguments

required.")

}

else

if

(nlhs

>

1)

{

mexErrMsgTxt("Too

many

output

arguments.")

}

/*

Check

the

dimensions

of

Y.

Y

can

be

4

X

1

or

1

X

4.

*/

m

=

mxGetM(Y_IN)

n

=

mxGetN(Y_IN)

if

(!mxIsDouble(Y_IN)

||

mxIsComplex(Y_IN)

||

(MAX(m,n)

!=

4)

||

(MIN(m,n)

!=

1))

{

mexErrMsgTxt("YPRIME

requires

that

Y

be

a

4

x

1

vector.")

}

/*

Create

a

matrix

for

the

return

argument

*/

YP_OUT

=

mxCreateDoubleMatrix(m,

n,

mxREAL)

/颤缺*

Assign

pointers

to

the

various

parameters

*/

yp

=

mxGetPr(YP_OUT)

t

=

mxGetPr(T_IN)

y

=

mxGetPr(Y_IN)

/*

Do

the

actual

computations

in

a

subroutine

*/

yprime(yp,t,y)

return

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12254214.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存