当前位置:网站首页>11. conditional statement if, switch

11. conditional statement if, switch

2022-06-11 23:43:00 fpga&matlab

FPGA Tutorial directory

MATLAB Tutorial directory

---------------------------------------------------------------------------------------

if

Condition is true Execute statement , The basic grammar is as follows :

if Conditions 1
    perform 1
elseif Conditions 2
    perform 2

elseif Conditions 3

      perform 3
else
    perform 4
end

Examples are as follows :

clc;
clear;
close all;
warning off;

 

Y = 10*rand


if Y>0 & Y<=2;
   B=1 ;
elseif Y>2 & Y<=4;
   B=2 ; 
elseif Y>4 & Y<=6;   
   B=3 ; 
else
  B=4 ;   
end

B

The meaning of this code is , Randomly produce a 0~10 Random number between Y, And then determine Y Size ,

If Y stay 0~2 Between ,B The assignment is 1,

If Y stay 2~4 Between ,B The assignment is 2,

If Y stay 4

原网站

版权声明
本文为[fpga&matlab]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011605277217.html