您的位置:广东在线游戏网 > 游戏资讯 > 请教matlab的exist函数的用法-请教matlab的exist函数的用法?

请教matlab的exist函数的用法-请教matlab的exist函数的用法?

作者:广东在线游戏网日期:

返回目录:游戏资讯


exist用来判断变量或函数是否存在:e68a84e8a2ade799bee5baa6366

 exist  Check if variables or functions are defined.
    exist('A') returns:
      0 if A does not exist
      1 if A is a variable in the workspace
      2 if A is an M-file on MATLAB's search path.  It also returns 2 when
           A is the full pathname to a file or when A is the name of an
           ordinary file on MATLAB's search path
      3 if A is a MEX-file on MATLAB's search path
      4 if A is a Simulink model or library file on MATLAB's search path
      5 if A is a built-in MATLAB function
      6 if A is a P-file on MATLAB's search path
      7 if A is a directory
      8 if A is a class (exist returns 0 for Java classes if you
        start MATLAB with the -nojvm option.)
 
    exist('A') or exist('A.EXT') returns 2 if a file named 'A' or 'A.EXT'
    and the extension isn't a P or MEX function extension.
 
    exist('A','var') checks only for variables.
    exist('A','builtin') checks only for built-in functions.
    exist('A','file') checks for files or directories.
    exist('A','dir') checks only for directories.
    exist('A','class') checks only for classes.
 
    If A specifies a filename, MATLAB attempts to locate the file, 
    examines the filename extension, and determines the value to 
    return based on the extension alone.  MATLAB does not examine 
    the contents or internal structure of the file.
 
    When searching for a directory, MATLAB finds directories that are part
    of MATLAB's search path.  They can be specified by a partial path.  It
    also finds the current working directory specified by a partial path,
    and subdirectories of the current working directory specified by
    a relative path.
 
    exist returns 0 if the specified instance isn't found.


exist在matlab中是用于检验某个参数变量是否存在或是否符合设定要求的函数,其不同的返回e69da5e887aae799bee5baa6366值代表的不同含义。
  exist name
  等价于 r=exist(name) ,在程序里面这样更加实用
  0 不存在则返回值
  1 name 可以是变量名,如果存在,返回值
  2 函数名、m 文件名,存在则返回值
  3 mex 文件、dll 文件,存在则返回值
  4 内嵌的函数,存在则返回值
  5 p码文件 , 存在则返回值
  6 目录,存在则返回值
  7 路径,存在则返回值
  8 Java class,存在则返回值

  A = exist('name','kind')
  name 可以是变量名,函数名、m 文件名、mex 文件、dll 文件、内嵌的函数、p码文件、目录、路径、Java class

  kind可以是 :
  builtin 内嵌函数
  class Java class
  dir 目录
  file 文件或者目录
  var 变量

  应用举例
  type = exist('plot') %说明当前目录下存在plot这个内嵌函数
  type =
  5
  
  X=rand(1,1)
  X =
  0.9593

  matabc

  r=exist('X')
  r =
  1

  r=exist('X','var')
  r =
  1
  matabc

  还有一个非常有用的,曾经在论坛讨论过
  如何判定一个结构体为空
  s = struct
  s =
  1x1 struct array with no fields.

  size(s) %用size不好判定
  ans =
  1 1

  matabc

  length(s) %length也一样
  ans =
  1

  r=exist('s.field') %用exist可以判定
  r =
  0

使用方法zd如下:

I=trapz(x,y)

其中x和y分别是自变量和对应的值,例如有函数y=x^3-2x-3,为了计算在[0,1]上的积分,可以这么做:

>> format compact

>> x=0:0.05:1;

>> y=x.^3-2.*x-3;

>> I=trapz(x,y)

I =

-3.7494

这个函数是可以直接使用经典积分理论计算的,精确值为 -15/4=-3.75,误差为0.016%。

扩展资料:

注意事项

MATLAB中的trapz()函数是基于复化梯形公式设计编写的,其一般调用格式为:

I=trpaz(x,y,dim)

其中x,y是观测数据,x可以为行向量或列向量,y可以为向量或矩阵,y的行数应等于x向量的元素个数;dim表示按维进行求积,若dim=1(缺省值),则按行求积,若dim=2,则按列求积。

如:计算函数y=x^3-2x-3,为了计算在[0,1]上的积分

x=0:0.05:1;

y=x.^3-2.*x-3;

trapz(x,y)

ans =

-3.7494



官方帮助,建议阅读:http:///help/techdoc/ref/exist.html
如果不存在dpos这个东西(变量,文件...)
dpos=0

如果ops的长度为1
pos0=[pos0;0;0]

相关阅读

关键词不能为空

标签导航

英文extra是什么意思,extra翻译解释,extra中文... extra additional区别 extra 和extend 区别 extra和additional有什么区别? 魔兽世界官方小说截止到现在一共出了多少本? 魔兽世界官方小说一共出了几本了?按魔兽历史时间顺序排列下书名... 魔兽世界官方小说一共有几本 魔兽世界官方小说一共有哪几部?游戏是按照官方小说来设计的吗?... 桂正和都出过哪些动漫,这些动漫和漫画 谁看过桂正和的漫画作品!给我推荐几部 ? 桂正和 的作品有哪些?? 请问桂正和有几部动漫作品? 游民星空下的武装突袭2:箭头行动免安装中文版解压完运行EXE... 武装突袭2 箭头行动 bad serial number g... 武装突袭2箭头行动出现这个,怎么办bad serial nu... 《武装突袭2》出现“bad serial number gi... 请教matlab的exist函数的用法 exist()函数在matlab中怎么用?求教大神~ 在matlab中 ~exist('im' 'var'),这... matlab中的exist是什么意思 魔兽争霸3不死族战术哪个好,请详细说明,我是新手 魔兽争霸不死族新手战术 魔兽不死族的最好战术是什么? 魔兽争霸中不死族的最强战术是什么? 求几个爆笑的笑话让女朋友开心一下! 照片P与不P的差距究竟在哪里? 流过产的女人还有人要吗? 发给女朋友温馨的短信 武侠群英传2朱宗潜怎么升级 武侠群英传2 如何修改,请高手指教,多谢 武侠群英传2攻略 武侠群英传2怎么我剧情文字都是看不懂的文字 求解决 2017全球总决赛EDGvsSKT输掉比赛问题出在哪 上次faker(SKT)拿妖姬是不是在夏季赛输给EDG的? LOL中,中国EDG真的打败棒子了吗,我特么不是做梦吧???... 厂长在edg比赛里表现的最好,最抢眼,拯救世界的是哪场比赛 魔兽争霸3不死族全攻略 魔兽争霸不死族攻略(最基本的,新手) 魔兽争霸3不死族新手怎么玩? 魔兽争霸不死族怎么玩 求几个国产好玩的RPG游戏 帮忙找几个国产RPG手机游戏 求个游戏 一个国产RPG 很老的游戏 一个边更新一边出 里边... 寻找一个2000年左右的国产rpg游戏 韩服比赛资源 Najin打 skt,妖姬5杀那次 求OGN2013夏季赛决赛视屏KTB VS SKT T1第五... 为什么看不了兮夜单杀faker的完整比赛视频?lol要为sk... 在一场不知道的职业联赛中,FAKER使用妖姬已经4傻,随后破... 音乐剧猫的观后感? 音乐剧《猫》观后感 音乐剧 猫 观后感 800字左右 魔域BOSS出现的时间和地点(所有地图的)!最好有图 魔域里哪里可以找到BOS图?