Matlab小实验

来源:互联网 发布:阿里云服务器规格 编辑:程序博客网 时间:2024/05/16 04:53

注意事项:

1.         先要顺利的完成opnetmatlab的联调工作。各种平台联调参数设置如上面所示。

2.         opnet中进行进程域,节点域,网络域模型的建立。关键编写管道阶段里面的程序。体现出matlab心道的确对opnet的仿真产生了影响。

3.         小站要放在一个校园网的小地图里面以保证视距可见;调节节点高度;设置发包的开始时间为0;提升容错门限值好在仿真变量中进行设置(我实验中用0.10.05)就可以明显的看到我们自己编写的管道阶段程序对仿真结果的影响。

mxArray  *T=NULL;

  double    time[10]={0,1,2,3,4,5,6,7,8,9};

     mxArray   *sun=NULL;

  double     *num_err;mxArray  *T=NULL;
  double    time[10]={0,1,2,3,4,5,6,7,8,9};

     mxArray   *sun=NULL;

  double     *num_err;
  char  suncmd[200]="a=1;b=30;c=a+b;";
//方法一为对每个matlab的运行语句进行逐个书写运行
T=mxCreateDoubleMatrix(1,10,mxREAL);
  memcpy((char*)mxGetPr(T),(char*)time,10*sizeof(double));
  engPutVariable(ep,"T",T);
  engEvalString(ep,"D=.5*(-9.8).*T.^2;");
  engEvalString(ep,"plot(T,D);");
  engEvalString(ep,"title('position vs. time for a falling object');");
  engEvalString(ep,"xlabel('tiem(seconds)');");
  engEvalString(ep,"ylabel('position(meters)');");
  
 方法二:把需要运行的程序放在一个字符数组中,一句话进行调用,最后只提取自己感兴趣的变量。
  engEvalString(ep,suncmd);
  if((sun=engGetVariable(ep,"c"))==NULL)
           {
           op_sim_end("'t get the variable","","","");
           }
  else
           {
           num_err = mxGetPr(sun);
           }
  printf("the number is: %d",(int) *num_err);
 
  方法三:把书写好的matlab的m文件写好后存在matlab的搜索路径里面。在c语言中只是对这个函数名进行直接调用就可以了。
  engEvalString(ep,"abc");
  if((sun=engGetVariable(ep,"c"))==NULL)
           {
           op_sim_end("'t get the variable","","","");
           }
  else
           {
           num_err = mxGetPr(sun);
           }
  printf("the number is: %d",(int) *num_err);
 
//  释放使用完的空间
  mxDestroyArray(T);
  mxDestroyArray(sun);
 

  char  suncmd[200]="a=1;b=30;c=a+b;";

//方法一为对每个matlab的运行语句进行逐个书写运行

T=mxCreateDoubleMatrix(1,10,mxREAL);

  memcpy((char*)mxGetPr(T),(char*)time,10*sizeof(double));

  engPutVariable(ep,"T",T);

  engEvalString(ep,"D=.5*(-9.8).*T.^2;");

  engEvalString(ep,"plot(T,D);");

  engEvalString(ep,"title('position vs. time for a falling object');");

  engEvalString(ep,"xlabel('tiem(seconds)');");

  engEvalString(ep,"ylabel('position(meters)');");

  

 方法二:把需要运行的程序放在一个字符数组中,一句话进行调用,最后只提取自己感兴趣的变量。

  engEvalString(ep,suncmd);

  if((sun=engGetVariable(ep,"c"))==NULL)

           {

           op_sim_end("'t get the variable","","","");

           }

  else

           {

           num_err = mxGetPr(sun);

           }

  printf("the number is: %d",(int) *num_err);

 

  方法三:把书写好的matlabm文件写好后存在matlab的搜索路径里面。在c语言中只是对这个函数名进行直接调用就可以了。

  engEvalString(ep,"abc");

  if((sun=engGetVariable(ep,"c"))==NULL)

           {

           op_sim_end("'t get the variable","","","");

           }

  else

           {

           num_err = mxGetPr(sun);

           }

  printf("the number is: %d",(int) *num_err);

 

//  释放使用完的空间

  mxDestroyArray(T);

  mxDestroyArray(sun);

 


0 0
原创粉丝点击