Está en la página 1de 7

New commands and functions

prod(A)
• If A is a vector, then prod(A) returns the product of the
elements.
• if A is a nonempty matrix, then prod(A) treats the columns of A
as vectors and returns a row vector of the products of each
column.
• if A is an empty 0-by-0 matrix, prod(A) returns 1.
clc
• clears all input andoutput from the Command Window display,
giving you a "cleanscreen.“
clear
• removes all variables from the current workspace, releasing
them from system memory.
clear name1 … nameN
• clear name1 ... nameN removesthe variables name1... nameN
from memory.
disp(x)
• displays the contents of X without printing the variable name.
• doesn’t display empty variables.

Note: ending the command or a function with semicolon (;)


will prevent showing result in the command window
>> a=[3:6]
a =
3 4 5 6
>> b=[a,a*10]
b =
3 4 5 6 30 40 50 60
>> c=b(5);
>> disp(c);
30
>> d=b([2:5])
d =
4 5 6 30
>> e=b([1 2 7 8])
e =
3 4 50 60
>> b(1)=prod(b([2:4]))
b =
120 4 5 6 30 40 50 60
>> b([2 4])=100
b =
120 100 5 100 30 40 50 60
After executing the previous commands the
command window will have these variables

To clear command window content (This will not affect the Workspace
variables it will clear the command content only)
>> clc
After executing the previous commands the
works space will have these variables

To clear all variables


>> clear

To clear a and b
>> clear a b
Exercises: write a suitable MATLAB command that will generate
the same result
>> a=[[1:5];linspace(6.7,8.15,5);[5:-1:1]] '

a=
1.0000 6.7000 5.0000
2.0000 7.0625 4.0000
3.0000 7.4250 3.0000
4.0000 7.7875 2.0000
5.0000 8.1500 1.0000

>> b=[a,a]
b=
1.0000 6.7000 5.0000 1.0000 6.7000 5.0000
2.0000 7.0625 4.0000 2.0000 7.0625 4.0000
3.0000 7.4250 3.0000 3.0000 7.4250 3.0000
4.0000 7.7875 2.0000 4.0000 7.7875 2.0000
5.0000 8.1500 1.0000 5.0000 8.1500 1.0000
a=
>> c = a(3,:) 1.0000 6.7000 5.0000
c= 2.0000 7.0625 4.0000
3.0000 7.4250 3.0000 3.0000 7.4250 3.0000
4.0000 7.7875 2.0000
>> d = a([2:3],[1:3]) 5.0000 8.1500 1.0000

d=
2.0000 7.0625 4.0000
3.0000 7.4250 3.0000

>> e = a([1:2:5],[1 2])


e=
1.0000 6.7000
3.0000 7.4250
5.0000 8.1500

>> f = e'

f=
1.0000 3.0000 5.0000
6.7000 7.4250 8.1500

También podría gustarte