Presentation is loading. Please wait.

Presentation is loading. Please wait.

Vlachopoulos Georgios Lecturer of Computer Science and Informatics Technological Institute of Patras, Department of Optometry, Branch of Egion Lecturer.

Similar presentations


Presentation on theme: "Vlachopoulos Georgios Lecturer of Computer Science and Informatics Technological Institute of Patras, Department of Optometry, Branch of Egion Lecturer."— Presentation transcript:

1 Vlachopoulos Georgios Lecturer of Computer Science and Informatics Technological Institute of Patras, Department of Optometry, Branch of Egion Lecturer of Biostatistics Technological Institute of Patras, Department of Physiotherapy, Branch of Egion Programming in Matlab Basic Control Structures

2 SymbolMeaning ==Equal >Greater Than >=Greater or Equal <Less Than <=Less or Equal ~=Not Equal Vlachopoulos Georgios

3 SymbolMeaning &Logical AND (conjugation) |Logical OR (disjunction) ~Logical NOT (negation) Vlachopoulos Georgios

4 ABA & BA | B~ A~B False True FalseTrueFalseTrue False TrueFalse TrueFalseTrue False Vlachopoulos Georgios Priority : &  |  ~

5  Selection Structures ◦ Simple Selection ◦ Composite Selection ◦ Nested Selection ◦ Multiple Selection  Iteration Structures Vlachopoulos Georgios

6 Simple Selection Vlachopoulos Georgios condition commands if condition commands end

7 Composite Selection Vlachopoulos Georgios Condition commands1 if condition commands1 else commands2 end commands2

8 Nested Selection Vlachopoulos Georgios if condition1 commands1 if condition 2 … else … end else if condition 3 … else … end

9 Multiple Selection Vlachopoulos Georgios if condition1 Commands1 elseif condition2 Commands2 elseif condition3 Commands3 …. elseif conditionN CommandsN else CommandsN+1 end Every multiple Selection can be written as nested

10  Example 1  Create an m-file that receives from the user a value and calculates the absolute value without the use of the corresponding elementary function  Example 2  Create an m-file that receives from the user the coefficients of a first order linear equation and solves it. Vlachopoulos Georgios

11  For  while Vlachopoulos Georgios Syntax for index=initial_value:final_value:step commands end Syntax While condition commands end

12 for i=1:100:1 disp (‘Your Name’) End i=1 while (i<=100) disp (‘Your Name’) i=i+1 end Vlachopoulos Georgios

13  Exercise 1a: Create an m-file to calculate the sum: s=1+2+3+…+10000  Exercise 1b: Convert the m-file to function that receives as argument the final value of the sum and calculates it.  Exercise 1c: Create an m-file to calculate the sum: s=1+2+3+… up to the value that the sum remains lower to 10000  Exercise 2: Create an m-file to calculate the product: p=3*5*7*…*21  Exercise 4: Create an m-file to calculate the sum: s=2 4 +4 4 +6 4 +…50 4 up to the value that the sum remains lower to 10000. Vlachopoulos Georgios

14  Exercise 5: Create an m-file to calculate the sum: S=5 66 +7 64 +9 62 +….51 20  Exercise 6: Create an m-file to calculate the sum: s=3!-4!+5!-6!+7!-…+21!  Exercise 7: Create an m-file to calculate the sum: Vlachopoulos Georgios


Download ppt "Vlachopoulos Georgios Lecturer of Computer Science and Informatics Technological Institute of Patras, Department of Optometry, Branch of Egion Lecturer."

Similar presentations


Ads by Google