Matlab Octave Control Elements: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * MATLAB/Octave")
 
Line 2: Line 2:


* [[MATLAB_Octave_CLI#Subjects|MATLAB/Octave]]
* [[MATLAB_Octave_CLI#Subjects|MATLAB/Octave]]
=Loops=
For all loops, 'break' and 'continue' work:
==for==
for i = <''range''> <''statement''> end;
for i = 1:10 disp(i) end;
The range can be a vector:
v = [2 4 6 8]
for i = v disp(i) end;
==while==
i = 1;
while i <= 5; i = i + 1; end;
=if=
if <''condition''>
    <''statement''>
endif;
if <''condition''>
    <''statement''>
else
    <''statement''>
endif;
if <''condition''>
    <''statement''>
elseif <''condition''>
    <''statement''>
...
else
      <''statement''>
endif;

Revision as of 23:30, 6 January 2018

Internal

Loops

For all loops, 'break' and 'continue' work:

for

for i = <range> <statement> end;
for i = 1:10 disp(i) end;

The range can be a vector:

v = [2 4 6 8]
for i = v disp(i) end;

while

i = 1;
while i <= 5; i = i + 1; end;

if

if <condition> 
    <statement> 
endif;
if <condition> 
    <statement> 
else 
    <statement> 
endif;
if <condition> 
    <statement> 
elseif <condition>
    <statement> 
...
else 
     <statement> 
endif;