Difference between revisions of "MatlabIntro"
From CCRMA Wiki
(→Basics) |
|||
Line 6: | Line 6: | ||
<pre> | <pre> | ||
− | >> x = | + | >> x = 1 |
x = | x = | ||
− | 1 | + | 1 |
</pre> | </pre> | ||
Line 16: | Line 16: | ||
<pre> | <pre> | ||
− | >> x = | + | >> x = 1; |
>> | >> | ||
</pre> | </pre> | ||
Line 29: | Line 29: | ||
</code> | </code> | ||
+ | |||
+ | * Inside a vector/matrix definition, commas or spaces separate elements row-wise | ||
+ | |||
+ | <pre> | ||
+ | >> x = [1 2 3 4 5] | ||
+ | </pre> | ||
+ | |||
+ | is the same as: | ||
+ | |||
+ | <pre> | ||
+ | >> x = [1,2,3,4,5] | ||
+ | </pre> | ||
+ | |||
+ | and they both generate a row vector. Semi-colons, instead, separate elements column-wise: | ||
+ | |||
+ | <pre> | ||
+ | >> x = [1;2;3;4;5] | ||
+ | </pre> | ||
== General tips == | == General tips == |
Revision as of 11:47, 21 September 2010
Basics
- Use semi-colon at the end of the line to prevent the output of the operation to be printed to the screen
>> x = 1 x = 1
vs.
>> x = 1; >>
Vector and Matrices
- Use square brackets to define a vector/matrix
x = [1 2 3 4 5]
- Inside a vector/matrix definition, commas or spaces separate elements row-wise
>> x = [1 2 3 4 5]
is the same as:
>> x = [1,2,3,4,5]
and they both generate a row vector. Semi-colons, instead, separate elements column-wise:
>> x = [1;2;3;4;5]
General tips
- Try to vectorize every operation if you can