Umal-qura university



Yüklə 0,73 Mb.
səhifə11/30
tarix23.12.2023
ölçüsü0,73 Mb.
#156716
1   ...   7   8   9   10   11   12   13   14   ...   30
Signal and Systems Manual - v2full

Branching constructs

MATLAB provides a number of language constructs for branching a program's control of flow.





        1. if‐end Construct : The most basic construct is: if

end
Here the condition is a logical expression that will evaluate to either true or false (i.e., with values 1 or 0). When a logical expression evaluates to 0, program control moves on to the next program construction. You should keep in mind that MATLAB regards A==B and A<=B as functions with values 0 or 1.
Example:
>> a = 1;
>> b = 2;
>> if a < b
c = 3;
end
>> c c = 3



        1. If‐else‐end Construct: Frequently, this construction is elaborated with

if

else

end




In this case if condition is 0, then program2 is executed.



        1. If-elseif-end Construct: Another variation is

if
elseif
end

Now if condition1 is not 0, then program1 is executed, if condition1 is 0 and if condition2 is not 0, then program2 is executed, and otherwise control is passed on to the next construction.


-------------------------TASK 03--------------------------


For 0 < a ≤ 16, find the values of C defined as follows:
C = 4ab for 1 ≤ a ≤ 8
ab for 8 < a ≤ 16
and b = 12.

-------------------------TASK 04--------------------------


Rewrite the following statements to use only one if statement.
if x < y
if z < 5
w = x*y*z end
end


      1. Yüklə 0,73 Mb.

        Dostları ilə paylaş:
1   ...   7   8   9   10   11   12   13   14   ...   30




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə