F.4Elementary examples 349
- Numerical value assignment and subtraction:
>> clear
>> a=1; b=-3; c=a-b
c=
4
- Number multiplication:
>> clear
>> a = 2.0; b=-3.5; c=a*b;
>> c
c=
-7
Typing the variablecdisplays its current value, in this case -7.
- Vector definition:
>> clear
>>v=[21]
v=
21
>> v(1)
ans =
2
>> v’ % transpose
ans =
2
1
Typingv(1)produces the first component of the vectorvas an answer. The
comment “transpose” is ignored since it is preceded by the comment delimiter
“%.” The answeransis, in fact, a variable evaluated byMatlab.
- Vector addition:
>>v=[12];u=[-1,-2];u+v
ans =
00