Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef MATLAB
- Engine *ep;
- mxArray *ARGS = NULL, *QCK = NULL, *MERGE = NULL, *DUAL = NULL, *QTI = NULL, *MTI = NULL, *INS = NULL;
- if (!(ep = engOpen(""))) {
- fprintf(stderr, "\nCan't start MATLAB engine\n");
- return EXIT_FAILURE;
- }
- ARGS = mxCreateNumericMatrix(maxArraySize / step, 1, mxINT32_CLASS, mxREAL);
- memcpy((void *)mxGetPr(ARGS), (void *)argsArray, maxArraySize / step * sizeof(int));
- DUAL = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
- for (int i = 0; i < maxArraySize / step; ++i) {
- for (int j = 0; j < 4; ++j) {
- memcpy((void *)(mxGetPr(DUAL) + i + maxArraySize / step * j), (void *)&dualpivotquickResult[i][j], sizeof(int));
- }
- }
- MTI = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
- for (int i = 0; i < maxArraySize / step; ++i) {
- for (int j = 0; j < 4; ++j) {
- memcpy((void *)(mxGetPr(MTI) + i + maxArraySize / step * j), (void *)&mergetoinsertionResult[i][j], sizeof(int));
- }
- }
- INS = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
- for (int i = 0; i < maxArraySize / step; ++i) {
- for (int j = 0; j < 4; ++j) {
- memcpy((void *)(mxGetPr(INS) + i + maxArraySize / step * j), (void *)&insertionResult[i][j], sizeof(int));
- }
- }
- QTI = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
- for (int i = 0; i < maxArraySize / step; ++i) {
- for (int j = 0; j < 4; ++j) {
- memcpy((void *)(mxGetPr(QTI
- ) + i + maxArraySize / step * j), (void *)&quicktoinsertionResult[i][j], sizeof(int));
- }
- }
- QCK = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
- for (int i = 0; i < maxArraySize / step; ++i) {
- for (int j = 0; j < 4; ++j) {
- memcpy((void *)(mxGetPr(QCK) + i + maxArraySize / step * j), (void *)&quickResult[i][j], sizeof(int));
- }
- }
- MERGE = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
- for (int i = 0; i < maxArraySize / step; ++i) {
- for (int j = 0; j < 4; ++j) {
- memcpy((void *)(mxGetPr(MERGE) + i + maxArraySize / step * j), (void *)&mergeResult[i][j], sizeof(int));
- }
- }
- engPutVariable(ep, "ARGS", ARGS);
- engPutVariable(ep, "QTI", QTI);
- engPutVariable(ep, "DUAL", DUAL);
- engPutVariable(ep, "MERGE", MERGE);
- engPutVariable(ep, "MTI", MTI);
- engPutVariable(ep, "INS", INS);
- engPutVariable(ep, "QCK", QCK);
- engEvalString(ep, "plot(ARGS, INS(:,3),'y', ARGS,MERGE(:,3),'b', ARGS,QCK(:,3),'m', ARGS,MTI(:,3),'c', ARGS,QTI(:,3),'r', ARGS,DUAL(:,3),'g');");
- engEvalString(ep, "title('Time vs. number of data');");
- engEvalString(ep, "xlabel('Data number');");
- engEvalString(ep, "ylabel('Time');");
- engEvalString(ep, "legend insertion merge quick mergeToInsertion quickToOnsertion dualQuick");
- engEvalString(ep, "legend location northwest");
- engEvalString(ep, "figure;");
- engEvalString(ep, "plot(ARGS, INS(:,2),'y', ARGS,MERGE(:,2),'b', ARGS,QCK(:,2),'m', ARGS,MTI(:,2),'c', ARGS,QTI(:,2),'r', ARGS,DUAL(:,2),'g');");
- engEvalString(ep, "title('Swaps vs. number of data');");
- engEvalString(ep, "xlabel('Data number');");
- engEvalString(ep, "ylabel('Swaps');");
- engEvalString(ep, "legend insertion merge quick mergeToInsertion quickToOnsertion dualQuick");
- engEvalString(ep, "legend location northwest");
- engEvalString(ep, "figure;");
- engEvalString(ep, "plot(ARGS, INS(:,1),'y', ARGS,MERGE(:,1),'b', ARGS,QCK(:,1),'m', ARGS,MTI(:,1),'c', ARGS,QTI(:,1),'r', ARGS,DUAL(:,1),'g');");
- engEvalString(ep, "title('Compares vs. number of data');");
- engEvalString(ep, "xlabel('Data number');");
- engEvalString(ep, "ylabel('Compares');");
- engEvalString(ep, "legend insertion merge quick mergeToInsertion quickToOnsertion dualQuick");
- engEvalString(ep, "legend location northwest");
- printf("Hit return to continue\n\n");
- fgetc(stdin);
- mxDestroyArray(ARGS);
- mxDestroyArray(QTI);
- mxDestroyArray(DUAL);
- mxDestroyArray(MERGE);
- mxDestroyArray(QCK);
- engEvalString(ep, "close;");
- engClose(ep);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement