Matlab - De C a Matlab

 
Vista:

De C a Matlab

Publicado por Luis (7 intervenciones) el 27/01/2017 18:36:04
Muy buenas, estoy creando de 0 el siguiente texto para Matlab (aquí copiado en lenguaje C) , sin embargo, estoy haciendo algo mal pero no se el que, si por favor alguien me pudiese hacer el favor de ayudar a traducir a Matlab el siguiente codigo de c me haría un gran favor, así podría ver donde me estoy equivocando... muchas gracias por adelantado!



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "mex.h"
#include "math.h"
 
* The program takes as inputs the vector of returns (y), the parameters THETA, BETA and the empirical quantile
* and produces as output a vector of VaR.
*/
void ComputeVaR(double THETA, double BETA[], double y[], double empiricalQuantile, double VaR[], int RowsOfBETA, int RowsOfy)
{
int i;
 
/* Initialize output variables */
VaR[0] = empiricalQuantile;
 
/* Start the loop */
for(i = 1; i < RowsOfy; i++)
{
// Symmetric Absolute Value
VaR[i] = BETA[0] + BETA[1] * VaR[i-1] + BETA[2] * (y[i-1]*(y[i-1]>0) - y[i-1]*(y[i-1]<0));
 
}
}
 
 
/***********************************************/
 
/* The gateway function */
 
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *y, *VaR, *BETA;
double THETA, empiricalQuantile;
int RowsOfBETA, RowsOfy;
 
/* Check for proper number of arguments */
if (nrhs != 4)
mexErrMsgTxt("Four inputs required.");
if (nlhs!=1)
mexErrMsgTxt("One output required.");
 
/* Check appropriate form of other inputs
.......
*/
 
/* Get the scalar input THETA and empiricalQuantile. */
THETA = mxGetScalar(prhs[0]);
empiricalQuantile = mxGetScalar(prhs[3]);
 
/* Create a pointer to the input vectors BETA and y */
BETA = mxGetPr(prhs[1]);
y = mxGetPr(prhs[2]);
 
/* Get the dimension of BETA and y */
RowsOfBETA = mxGetM(prhs[1]);
RowsOfy = mxGetM(prhs[2]);
 
/* Set the output pointer */
plhs[0] = mxCreateDoubleMatrix(RowsOfy, 1, mxREAL);
 
/* Create a C pointer to a copy of the output vectors */
VaR = mxGetPr(plhs[0]);
 
/* Call the C subroutine */
ComputeVaR(THETA, BETA, y, empiricalQuantile, VaR, RowsOfBETA, RowsOfy);
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder