result = engGetVariable(ep,"X")

转载 2012年03月22日 21:00:30
/* $Revision: 1.8.4.1 $ */
/*
* engdemo.c
*
* This is a simple program that illustrates how to call the MATLAB
* Engine functions from a C program.
*
* Copyright 1984-2003 The MathWorks, Inc.
* All rights reserved
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "engine.h"
#define BUFSIZE 256
#pragma comment(lib,"libeng.lib")
#pragma comment(lib,"libmx.lib")
int main()
{
Engine *ep;
mxArray *T = NULL, *result = NULL;
char buffer[BUFSIZE+1];
double time[10] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
/*
* Start the MATLAB engine locally by executing the string
* "matlab"
*
* To start the session on a remote host, use the name of
* the host as the string rather than \0
*
* For more complicated cases, use any string with whitespace,
* and that string will be executed literally to start MATLAB
*/
if (!(ep = engOpen("\0"))) {
   fprintf(stderr, "\nCan't start MATLAB engine\n");
   return EXIT_FAILURE;
}
/*
* PART I
*
* For the first half of this demonstration, we will send data
* to MATLAB, analyze the data, and plot the result.
*/
/*
* Create a variable for our data
*/
//T = mxCreateDoubleMatrix(1, 10, mxREAL);
//memcpy((void *)mxGetPr(T), (void *)time, sizeof(time));
/*
* Place the variable T into the MATLAB workspace
*/
//engPutVariable(ep, "T", T);
/*
* Evaluate a function of time, distance = (1/2)g.*t.^2
* (g is the acceleration due to gravity)
*/
//engEvalString(ep, "D =0.5.*(-9.8).*T.^2;");
/*
* Plot the result
*/
//engEvalString(ep, "plot(T,D);");
//engEvalString(ep, "title('Position vs. Time for a falling object');");
//engEvalString(ep, "xlabel('Time (seconds)');");
//engEvalString(ep, "ylabel('Position (meters)');");
/*
* use fgetc() to make sure that we pause long enough to be
* able to see the plot
*/
//printf("Hit return to continue\n\n");
//fgetc(stdin);
/*
* We're done for Part I! Free memory, close MATLAB engine.
*/
//printf("Done for Part I.\n");
//mxDestroyArray(T);
//engEvalString(ep, "close;");
/*
* PART II
*
* For the second half of this demonstration, we will request
* a MATLAB string, which should define a variable X. MATLAB
* will evaluate the string and create the variable. We
* will then recover the variable, and determine its type.
*/
/*
* Use engOutputBuffer to capture MATLAB output, so we can
* echo it back. Ensure first that the buffer is always NULL
* terminated.
*/
buffer[BUFSIZE] = '\0';
engOutputBuffer(ep, buffer, BUFSIZE);
while (result == NULL) {
     char str[BUFSIZE+1];
		/*
      * Get a string input from the user
      */
     printf("Enter a MATLAB command to evaluate. This command should\n");
     printf("create a variable X. This program will then determine\n");
     printf("what kind of variable you created.\n");
     printf("For example: X = 1:5\n");
     printf(">> ");
     fgets(str, BUFSIZE, stdin);
		   /*
      * Evaluate input with engEvalString
      */
     engEvalString(ep, str);
		  /*
      * Echo the output from the command. First two characters are
      * always the double prompt (>>).
      */
     printf("%s", buffer);
		   /*
      * Get result of computation
      */
     printf("\nRetrieving X...\n");
         if ((result = engGetVariable(ep,"X")) == NULL)
       printf("Oops! You didn't create a variable X.\n\n");
         else {
           printf("X is class %s\t\n", mxGetClassName(result));
		   printf("X[0]=%lf\n",*mxGetPr(result));
          }
}
/*
	* We're done! Free memory, close MATLAB engine and exit.
	*/
	printf("Done!\n");
	mxDestroyArray(result);
	engClose(ep);
	return EXIT_SUCCESS;
}

相关文章推荐

Activiti5学习笔记(一)简单的预算审批

汇编——win32下计算result=m-n*x

编写Windows 32位控制台程序,计算result=m-n*x的值。要求提示用户输入32位带符号整数m, n, x,并显示计算结果。屏幕格式为: m=                    ...
  • RAUL_AC
  • RAUL_AC
  • 2013年03月24日 21:26
  • 892

No error message available, result code: E_FAIL(0x80004005)

做上传Excel文件这个功能的时候,遇到个奇怪的事情。 我的程序里上传Excel文件的过程是这样的: 1.将用户选择上传的文件保存到服务器上 2.使用 Provider=Microsoft.Ac...

鬼吹灯之精绝古城.EP01-18 高清

◎译  名 鬼吹灯网剧版 ◎片  名 鬼吹灯之精绝古城 ◎年  代 2016 ◎国  家 中国大陆 ◎类  别 剧情/悬疑/惊悚 ◎语  言 汉语普通话 ◎上映日期 2016-12-19(...
  • pobing_
  • pobing_
  • 2017年01月16日 23:16
  • 65

EP3C5E144C8N的PCB封装在哪里?

一、打开altera的官网,找到“支持”一栏; 二、选择“文档资料”一栏; 三、选择对应的FPGA型号,Cyclone Ⅲ(&LS)型号。 四、选择CycloneⅢ Package Sp...
  • crjmail
  • crjmail
  • 2017年03月27日 08:39
  • 520

backtrack5安装edup ep-n1566无线网卡的rt3070驱动

最近研究了下主流的无线路由器密码破解方案,主流的有两种

脱壳一 常见语言和编译器的EP入口地址内类型

那些年我们一起脱过的衣裳-脱壳(上) 转载自乌云知识库 0x01 简介 http://drops.wooyun.org/tips/8296文中提到了脱壳七大法,然而实际上我有八大法!...

EP6: Wythoff’s Game (威佐夫博弈)

此篇为转载,做收藏之用,以下是作者的版权信息: 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明 http://www.blogbus.com/yjq24-logs/426...

STM32 USB 程序将BULK EP改成双缓冲机制后,接收OUT数据的速度从原先的500KB/S

STM32 USB 程序将BULK EP改成双缓冲机制后,接收OUT数据的速度从原先的500KB/S, 收藏 前天测试自己编写的USB驱动程序时候发现从主机到STM32的OUT传输(主机到设备)速率竟...

usb camera mbox使用时出现“cannot get freq at ep”

在项目中遇到一个usb摄像头无法正常录音的问题,而其他usb camera都可以正常工作。因此查询这个usb camera在录音的时候有什么不同的地方,发现用这个usb camera录音的时候总是打印...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:result = engGetVariable(ep,"X")
举报原因:
原因补充:

(最多只允许输入30个字)