⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matlab-c.txt

📁 一个用MATLAB编写的优化控制工具箱
💻 TXT
字号:
Using MATLAB to plot data generated by other programs:For the C language:/* This file may be compiled using the format:     gcc filename.c -o exefile -lm   Running this program creates a file named "outvar.dat".  The    data for a cosine and sine function is calaculated and saved   as three columns of numbers.   To plot the data within MATLAB, you may use the following from a   MATLAB window:>> load outvar.dat>> x = outvar(:,1);>> y = outvar(:,2);>> z = outvar(:,3);>> plot(x,y)>> hold on>> plot(x,z) >> hold off*/#include <stdio.h>        /* standard Input/Output */#include <stdlib.h>       /* standard library      */#include <math.h>         /* math library          */main(){  double x,y,z;           /* variables used */  FILE *fp;               /* file pointer   *//* Check to see if there are any file errors.        *//* This will either create a new file OUTVAR.DAT, or *//* write over an existing version of the file.       */  if ( (fp = fopen("outvar.dat", "w")) == NULL)    {      printf("Cant open OUTVAR.DAT \n");      exit(1);    }/* This loop is used to save y=cos(x).*/  for(x=0; x<=10; x += 0.1)    {      y = cos(x);      z = sin(x);      fprintf(fp, "%f %f %f",x,y,z);   /* save the x and y values */      fprintf(fp, "\n");               /* create a line break     */    }  fclose(fp);                          /* close the file */}For Other High Level Languages: If you want to use Fortran, Pascal, Basic, or some other language and MATLAB to generate plots you proceed in a similar manner to how you do for C.  Note that any space delimited ASCII data file can be read by MATLAB (i.e. columns of data seperated by any number of "blank" spaces).  Hence, if you use any high level language simply output your data into an ASCII file and use the MATLAB commands given above.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -