【发布时间】:2016-02-04 08:22:24
【问题描述】:
我目前在带有 R2015b 的 Matlab 中使用名为 Policy Search 工具箱的工具箱。我“混合”了所有文件,工具箱工作得很好。 计算微分方程的 .cpp 文件之一,在 Matlab 中的一个函数中计算并使用一个值。 由于工具箱与数据管理器一起使用,我不能只在模拟过程之后调用变量。 由于该函数是工具箱的巨大(!)构造的一部分,因此我不能只修改输出或复制粘贴并在其他地方调用该函数。
#include "mex.h"
#include <math.h>
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
// Input
double
*startPosition = mxGetPr(prhs[0]),
.......// some more variables ...
// Output
plhs[0] = mxCreateDoubleMatrix(numJoints, numTrajectorySteps, mxREAL);
plhs[1] = mxCreateDoubleMatrix(numJoints, numTrajectorySteps, mxREAL);
plhs[2] = mxCreateDoubleMatrix(numJoints, numTrajectorySteps, mxREAL);
double
*Y = mxGetPr(plhs[0]),
*Yd = mxGetPr(plhs[1]),
*Ydd = mxGetPr(plhs[2]);
.......// some more code ...
double smoothedForcingFunction = iTrajectoryStep < numForcedSteps ? forcingFunction[oldI] : 0;
double Ydd = (alpha_x*(beta_x*(goalTemp-Y[oldI])+(goalVel-Yd[oldI])/ tau) +(amplitude[iJoint]*smoothedForcingFunction))*tau * tau;
// simplectic Euler
Yd[curI] = Yd[oldI] + dt*Ydd;
Y[curI] = Y[oldI] + dt*Yd[curI];
}
}
// printf("Done\n");
mxDestroyArray(xData);
mxDestroyArray(xdData);
mxDestroyArray(tData);
}
我怎样才能将YDD(底部的计算值)从那里取出到我的 Matlab 工作区中?是否有一种“公共 goto 工作区作为输出 plz!” C++ 中的函数?
非常感谢您的帮助!
【问题讨论】:
-
Ydd的大小和数据类型是多少?