zoukankan      html  css  js  c++  java
  • MATLAB 的条件分支语句

    MATLAB 的条件分支语句:

    1)if...end 

    2)if...else...end 

    3) if...elseif...elseif...else...end 

    a=30;
    if a<20
        fprintf('
    a is less than 20
    ');
    else
        fprintf('a is larger than 20')
    end
    fprintf('a is %d
    ',a);

    结果输出:

    4)switch语句

     switch语句语法:

    switch <switch_expression>
       case <case_expression>
         <statements>
       case <case_expression>
         <statements>
         ...
         ...
       otherwise
           <statements>
    end

    例如:

    grade = 'B';
       switch(grade)
       case 'A' 
          fprintf('Excellent!
    ' );
       case 'B' 
           fprintf('Well done
    ' );
       case 'C' 
          fprintf('Well done
    ' );
       case 'D'
          fprintf('You passed
    ' );
       
       case 'F' 
         fprintf('Better try again
    ' );
         
       otherwise
         fprintf('Invalid grade
    ' );
       end

    结果:

  • 相关阅读:
    软件体系结构课后作业03
    Struts2初步认识
    springboot1
    pytorch安装
    classifier of chains
    python错误集锦
    svm-惩罚因子
    毕设笔记1----div样式
    SQLite
    MVC实例应用模式
  • 原文地址:https://www.cnblogs.com/shenxiaolin/p/9234576.html
Copyright © 2011-2022 走看看