Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdlib.h>
00012 #include <stdio.h>
00013 #include <string.h>
00014 #include "engine.h"
00015 #define BUFSIZE 256
00016
00017 int main()
00018
00019 {
00020 Engine *ep;
00021 mxArray *T = NULL, *result = NULL;
00022 char buffer[BUFSIZE+1];
00023 double time[10] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
00024
00025
00026
00027
00028
00029 if (!(ep = engOpen(""))) {
00030 fprintf(stderr, "\nCan't start MATLAB engine !!!\n");
00031 return EXIT_FAILURE;
00032 }
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 T = mxCreateDoubleMatrix(1, 10, mxREAL);
00045 memcpy((void *)mxGetPr(T), (void *)time, sizeof(time));
00046
00047
00048
00049 engPutVariable(ep, "T", T);
00050
00051
00052
00053
00054
00055 engEvalString(ep, "D = .5.*(-9.8).*T.^2;");
00056
00057
00058
00059
00060 engEvalString(ep, "plot(T,D);");
00061 engEvalString(ep, "title('Position vs. Time for a falling object');");
00062 engEvalString(ep, "xlabel('Time (seconds)');");
00063 engEvalString(ep, "ylabel('Position (meters)');");
00064
00065
00066
00067
00068
00069 printf("Hit return to continue\n\n");
00070 fgetc(stdin);
00071
00072
00073
00074 printf("Done for Part I.\n");
00075 mxDestroyArray(T);
00076 engEvalString(ep, "close;");
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 buffer[BUFSIZE] = '\0';
00095 engOutputBuffer(ep, buffer, BUFSIZE);
00096 while (result == NULL) {
00097 char str[BUFSIZE+1];
00098
00099
00100
00101 printf("Enter a MATLAB command to evaluate. This command should\n");
00102 printf("create a variable X. This program will then determine\n");
00103 printf("what kind of variable you created.\n");
00104 printf("For example: X = 1:5\n");
00105 printf(">> ");
00106
00107 fgets(str, BUFSIZE, stdin);
00108
00109
00110
00111
00112 engEvalString(ep, str);
00113
00114
00115
00116
00117 printf("%s", buffer);
00118
00119
00120
00121
00122 printf("\nRetrieving X...\n");
00123 if ((result = engGetVariable(ep,"X")) == NULL)
00124 printf("Oops! You didn't create a variable X.\n\n");
00125 else {
00126 printf("X is class %s\t\n", mxGetClassName(result));
00127 }
00128 }
00129
00130
00131
00132
00133 printf("Done!\n");
00134 mxDestroyArray(result);
00135 engClose(ep);
00136
00137 return EXIT_SUCCESS;
00138 }