通行证│用户名: 密码: 验证码: 验证码,看不清楚?请点击刷新验证码 电信网通铁通移动   在线
资源搜索:
热门搜索:Linux VB C语言 PhotoShop Flash TCP/IP
   首页 | 文章 | 软件 | 动画 | 资源 | 励志 | 骗术 | 论坛 | 邮箱 | 会员中心 | 军事 | 科技 | 博客 | 图片 | 商城 | 最新更新 | 800g资源 | 爱心黑客
您现在的位置: 爱国者黑客 >> 资源 >> 机械电子 >> MATLAB >> Matlab基础 >> 文章正文

M文件举例
责任编辑:admin   更新日期:2005-8-6

    为了演示If-Else-End结构,考虑精通MATLAB工具箱中函数mmono,它检查一个向量的单调性。

                   » mmono(1:12)     %  strictly increasing input

                   ans =

                        2

                   » mmono([1:12  12  13:24])     %  non decreasing input

                   ans =

                        1

                   » mmono([1  3  2  -1])     %  not monotonic in any sense

                   ans =

                        0

                   » mmono([12:-1:0  0  -1])     %  non increasing

                   ans =

                       -1

                   » mmono(12:-1:0)     %  strictly decrasing

                   ans =

                       -2

这个精通MATLAB工具箱的函数主体给出如下:

          function f=mmono(x)

          %  MMONO Test for monotonic vector.

          %  MMONO(x) where x is a vector return:

          %    2 if x is strictly increasing,

          %    1 if x is non decreasing,

          %   -1 if x is non increasing,

          %   -2 if x is strictly decreasing,

          %    0 otherwise.

          %  Copyright (c) 1996 by Prentice-Hall,Inc.

          x=x(:);        %  make x a column vector

          y=diff(x);      %  find differences between consecutive elements

          if all(y>0)      %  test for strict first

                     f=2;

          elseif all(y>=0)

                     f=1;

          elseif all(y<0)   %  test for strict first

                     f=-2;

          elseif all(y<=0) 

                     f=-1;

          else

                     f=0;   %  otherwise response

          end

    函数mmono直接利用了If-Else-End结构。由于严格单调是一般单调的子集,首先检验严格的单调是必要的,因为在所碰见的第一个真值分支里,其语句执行之后,结构就结束。

 
  • 上一篇文章:
  • 下一篇文章:
  • 热门文章
    Olldbg常见问题
    汇编语言的艺术(组合语言的艺术)--观
    汇编语言的艺术(组合语言的艺术)--准
    汇编语言的艺术(组合语言的艺术)--基
    汇编语言的艺术(组合语言的艺术)--基
    汇编语言---程式设计 (4)
    虚拟8086模式
    SYS命令使用说明
    javascript + CSS 实现动态菜单显
    推荐文章
    自制Windows XP SP2自动安装光盘
    SQLServer注入工具改进版 v1.02
    使用photoshop CS进行自然美肤
    Photoshop绘制诺基亚手机
    PHOTOSHOP制作秋日之梦
    PHOTOSHOP鼠绘名模王爱萍
    Photoshop制作晶莹飞溅的水珠
    教你用PHOTOSHOP做放大镜
    鼠绘美女及服装修画全过程