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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
//#include "appelMatlab.h"
#include "creer_Tableau.h"
#include <iostream>
#include "engine.h"
#include "AllocationDynamique.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//#include "engine.h"
#define BUFSIZE 256
void main(){
char buffer[BUFSIZE+1];
buffer[BUFSIZE] = '\0';
double** v = NULL;
int** g = NULL;
double** z = NULL;
int taillev=0;
int tailleg=0;
creer(0, 1, 0, 1, 0.1, taillev, tailleg, v, g, z);
Engine *ep;
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");// Call engOpen with a NULL string. This starts a MATLAB process on the current host using the command "matlab".
return;
}
cout << "Creation des matrices vides de X, Y et Z" << endl;
mxArray *X=NULL;
X = mxCreateDoubleMatrix(1, taillev, mxREAL);
mxArray *Y=NULL;
Y = mxCreateDoubleMatrix(1, tailleg, mxREAL);
mxArray *Z=NULL;
Z = mxCreateDoubleMatrix(taillev, tailleg, mxREAL);
cout << "Remplissage dans Matlab des matrices vides de X, Y et Z" << endl;
memcpy((void *)mxGetPr(X), (void *)v, sizeof(double)*1*taillev);
memcpy((void *)mxGetPr(Y), (void *)g, sizeof(double)*1*tailleg);
memcpy((void *)mxGetPr(Z), (void *)z, sizeof(double)*taillev*tailleg);
cout << "ici" << z[1][1] << endl;
cout << "Placement dans Matlab des matrices, X, Y et Z" << endl;
engPutVariable(ep, "X", X);//Place the variable X into the MATLAB workspace
engPutVariable(ep, "Y", Y);
engPutVariable(ep, "Z", Z);
cout << "dessiner les matrices dans Matlab" << endl;
engEvalString(ep, "surf(X,Y,Z);");
engOutputBuffer(ep, buffer, BUFSIZE);
char str[BUFSIZE+1];
cout << " tape un truc" << endl;
fgets(str, BUFSIZE, stdin);//Get a string input from the user
engEvalString(ep, str);//Evaluate input with engEvalString
printf("%s", buffer);//Echo the output from the command.
fgetc(stdin);
mxDestroyArray(X);
mxDestroyArray(Y);
mxDestroyArray(Z);
desalloueTabStatDeuxDimDouble(1, v);
desalloueTabStatDeuxDimInt(1, g);
desalloueTabStatDeuxDimDouble(taillev, z);
fgetc(stdin);
engClose(ep);//close MATLAB engine
return;//exit
} |
Partager