Matlab Tutorial 7: Common Programming Structures and Conditional Statements


Timing

In some cases there could be limitations of time. How long a certain calculation are supposed to continue and therefore Matlab provides us with a tool to find out what parts of a program that are time-consuming. This is accomplished by the command profile.
Let us have a look on our previously used m-file nonsens. Write!

profile on % starts timer
nonsens
profile off
profile report % Opens a html-page, where you can find a table.
% Click on the link nonsens.
% Consumed time for each command line are shown.

Logical operators
& Logical and
| Logical or
~ Logical not
Finally we will look on three examples to see how we can use these operators.

% Logical AND
x=input('Give a x: ')
k=input('Give a k: ')
if x==3&k<100 % if x=3 and k<100, then display ”Hello !”
disp('Hello !')
else
disp('Hi !') % otherwise display ”Hi !”
end
% Logical OR
x=input('Give a x: ')
k=input('Give a k: ')
if x==3|k<100 % if x=3 or k<100, then display ”Hello !”
disp('Hello !')
else
disp('Hi !') % otherwise display ”Hi !”
end
% Logical NOT
k=input('Give a k: ')
if ~(k<100) % if k>=100, then display ”Hello !”
disp('Hello !')
else % otherwise display ”Hi !”
disp('Hi !')
end

Related posts:

  1. Matlab Tutorial 3: Strings in Matlab
  2. Matlab Tutorial 2: Matrices in Matlab
  3. Matlab Tutorial 4: Data Analysis and Statistics with Matlab
  4. Matlab Tutorial 1: Hello world, plotting, mathematical functions and file types

Pages: 1 2 3 4

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment