Matlab - Leer codigo C en Matlab

 
Vista:

Leer codigo C en Matlab

Publicado por Luis (7 intervenciones) el 24/01/2017 11:52:48
Muy buenas,

cuando intento llamar a una función en lenguaje C desde Matlab me sale el siguiente mensaje: "Undefined function 'SAVloop' for input arguments of type 'double'."

¿Puede ser que tenga que instalar un compiler? No tengo ninguno instalado. He intentado instalar el Visual Studio y el SDK pero no lo consigo y ya estoy desesperado.

Por favor, si alguien me puede echar un mano se lo agradeceré mucho.

Muchas gracias por adelantado.

Un saludo,

Luis.
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

Leer codigo C en Matlab

Publicado por Luis (7 intervenciones) el 27/01/2017 18:24:19
Muchas gracias por tu respuesta, sin embargo no consigo solucionar el problema. Me he decantado por programar de 0 el script en lenguaje Matlab, sin embargo, al no tener conocimiento de c, tengo muchas lagunas sobre algunas partes :( Os copio el script de c y en caso de que me pudieseis echar un cable traduciendolo os lo agradeceria mucho, así vería donde me estoy equivocando exactamente, ahi va el código en lenguaje c:

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 respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar